You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-dev@xerces.apache.org by Sanjay Mishra <sm...@etouch.net> on 2002/04/03 21:16:32 UTC

Entity Reference

Hi,

I'm trying to use an Entity Refrence in my XML, but during parsing
Xerces2.0 does not returns the entity value. It returns the "null"
value. I'm using the Entity in one of my xml's attribute.

Following are the XML and DTD:

DTD**********************************************
<?xml encoding="UTF-8"?>
<!ENTITY img-path 'http://localhost:7001/cm/images/'>
**********************************************

XML**********************************************
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE cmlib SYSTEM "file:///c:/xmltest/cmlib.dtd">
<document>
 <img src="&img-path;doc.gif"/>
</document>
**********************************************

Here when I write code something like this:
System.out.println(nd.getAttributes().getNamedItem("src").getNodeValue());

the output comes out is:
nulldoc.gif

I'm properly setting system id.

Is there anyone who have any idea about this, please tell me where I'm
doing wrong. It will be great!!

thanks,
Sanjay Mishra


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-dev-help@xml.apache.org


Re: Entity Reference

Posted by Andy Clark <an...@apache.org>.
Sanjay Mishra wrote:
> Thank you very much for your time which you have spent in looking the
> matter. I'm using "Xerces2 Java Parser 2.0.0 (beta) Release". I have not
> set any feature (NAMESPACES_FEATURE_ID etc..) in my program. Do I need to
> set them? Also do I need to implement EntityResolver.

You are using code that was released last year. Please upgrade
to the latest version of the parser, Xerces 2.0.1. You can get
the new version from the following URL:

  http://xml.apache.org/dist/xerces-j/

-- 
Andy Clark * andyc@apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-dev-help@xml.apache.org


Re: Entity Reference

Posted by Sanjay Mishra <sm...@etouch.net>.
Hello Andy,

Thank you very much for your time which you have spent in looking the
matter. I'm using "Xerces2 Java Parser 2.0.0 (beta) Release". I have not
set any feature (NAMESPACES_FEATURE_ID etc..) in my program. Do I need to
set them? Also do I need to implement EntityResolver.

Here is the code:
   try{
    DOMParser parser = new DOMParser();
    InputSource is = new InputSource(new FileInputStream(new
File(args[0])));
    is.setSystemId(args[0]);
    parser.parse(is);
    Document doc = parser.getDocument();
    Node nd = (Node)doc.getDocumentElement().getFirstChild();
    while(nd != null){
     if (nd.getNodeType()==Node.ELEMENT_NODE){
      if(nd.getAttributes() != null){

System.out.println(nd.getAttributes().getNamedItem("src").getNodeValue());

      }
     }
     nd = nd.getNextSibling();
    }
   }catch(Exception _ex){System.err.println(_ex.toString());}

DTD:--
<?xml encoding="UTF-8"?>
<!ENTITY img-path 'http://localhost/myapp/images/'>

XML:--

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE cmlib SYSTEM "file:///c:/myapp/cmlib.dtd">
<document>
 <img src="&img-path;doc.gif"/>
</document>

Thanks,
Sanjay Mishra




Andy Clark wrote:

> Sanjay Mishra wrote:
> > I'm trying to use an Entity Refrence in my XML, but during parsing
> > Xerces2.0 does not returns the entity value. It returns the "null"
> > value. I'm using the Entity in one of my xml's attribute.
>
> Using your sample files (but modifying them a bit to point to
> local files), I don't see the problem that you're experiencing.
> Could you go into more detail about how you are using the parser?
>
> For example, what version of the parser are you using? (I used
> Xerces 2.0.1 with your sample document.) Also, what settings are
> you using? etc...
>
> --
> Andy Clark * andyc@apache.org
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-j-dev-help@xml.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-dev-help@xml.apache.org


Re: Entity Reference

Posted by Andy Clark <an...@apache.org>.
Sanjay Mishra wrote:
> I'm trying to use an Entity Refrence in my XML, but during parsing
> Xerces2.0 does not returns the entity value. It returns the "null"
> value. I'm using the Entity in one of my xml's attribute.

Using your sample files (but modifying them a bit to point to 
local files), I don't see the problem that you're experiencing. 
Could you go into more detail about how you are using the parser?

For example, what version of the parser are you using? (I used
Xerces 2.0.1 with your sample document.) Also, what settings are 
you using? etc...

-- 
Andy Clark * andyc@apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-dev-help@xml.apache.org