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 Tom Cook <tk...@subcorp.com.au> on 2001/01/29 05:29:22 UTC

getElementById

Hi,

This problem has come to call my sanity into serious question, so now I'm
asking for help.

I have this DTD for an XML document:

<!ELEMENT document (tag)>
<!ELEMENT tag>

<!ATTLIST document id ID #IMPLIED>
<!ATTLIST tag id ID #IMPLIED>

I then have this document:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE document PUBLIC "-//W3C//XML XML//EN"
"file:/home/tkcook/dev/test/test.dtd">

<document id="id1">
  <tag id="id2"/>
</document>

When I create a validating parser and parse this with this code:

/* javax.xml.parsers.DocumentBuilderFactory=org.apache.xerces.jaxp.DocumentBuilderFactoryImpl */
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setValidating( true ); DocumentBuilder builder =
factory.newDocumentBuilder();

Document doc = builder.parse( "file:/home/tkcook/dev/test/test.xml" ); /* The above document */
System.out.println( doc.getElementById( "id1" ).getNodeName() );

then the last line gives a null pointer exception, apparently because there is
no tag with id "id1".

Sooooo... I hacked around a bit with DOMParser.java, and found that the parser
thinks the type of the 'id' tag is CDATA, even though it's specified as ID in
the DTD!

Can someone tell me what I'm doing wrong, please?

Tom
-- 
Systems Development    	       	      | Phone: +61 8 8348 7645
Australian Submarine Corporation      |	"From the moment I picked your book up until the instant I put
Mersey Road			      |	 it down, I was convulsed with laughter. I intend to read it,
Outer Harbour, SA, 5018		      |  one day."  --  Groucho Marx, The Insult Book

Re: getElementById

Posted by Tom Cook <tk...@subcorp.com.au>.
On Tue, 30 Jan 2001, you wrote:
> Hi, Tom,
> What version of Xerces are U using? I have checked out the latest code
> from CVS and it works fine..

1.2.3 didn't work for me.  1.2.1 seems to work fine.  I think I might have been
having trouble making it validate correctly though.  I think that was my
problem.

Tom

Re: getElementById

Posted by Elena Litani <hl...@jtcsv.com>.
Hi, Tom,
What version of Xerces are U using? I have checked out the latest code
from CVS and it works fine..

Elena

Tom Cook wrote:
> 
> Hi,
> 
> This problem has come to call my sanity into serious question, so now I'm
> asking for help.
> 
> I have this DTD for an XML document:
> 
> <!ELEMENT document (tag)>
> <!ELEMENT tag>
> 
> <!ATTLIST document id ID #IMPLIED>
> <!ATTLIST tag id ID #IMPLIED>
> 
> I then have this document:
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <!DOCTYPE document PUBLIC "-//W3C//XML XML//EN"
> "file:/home/tkcook/dev/test/test.dtd">
> 
> <document id="id1">
>   <tag id="id2"/>
> </document>
> 
> When I create a validating parser and parse this with this code:
> 
> /* javax.xml.parsers.DocumentBuilderFactory=org.apache.xerces.jaxp.DocumentBuilderFactoryImpl */
> DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
> factory.setValidating( true ); DocumentBuilder builder =
> factory.newDocumentBuilder();
> 
> Document doc = builder.parse( "file:/home/tkcook/dev/test/test.xml" ); /* The above document */
> System.out.println( doc.getElementById( "id1" ).getNodeName() );
> 
> then the last line gives a null pointer exception, apparently because there is
> no tag with id "id1".
> 
> Sooooo... I hacked around a bit with DOMParser.java, and found that the parser
> thinks the type of the 'id' tag is CDATA, even though it's specified as ID in
> the DTD!
> 
> Can someone tell me what I'm doing wrong, please?
> 
> Tom
> --
> Systems Development                   | Phone: +61 8 8348 7645
> Australian Submarine Corporation      | "From the moment I picked your book up until the instant I put
> Mersey Road                           |  it down, I was convulsed with laughter. I intend to read it,
> Outer Harbour, SA, 5018               |  one day."  --  Groucho Marx, The Insult Book
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-j-dev-help@xml.apache.org