Subject: Using getElementById
Posted By: Frank Huddleston Post Date: 11/3/2005 12:27:23 PM
Greetings,

   I implemented a family tree using the XML version given by Micheal Kay in his XSLT book, but now I'd like to make a standalone java application from it. I'm reading in the file and creating an XML document (DOM), and trying to use the Apache XALAN getElementById method to retrieve an individual's record by id; this has the ID attibute like so:
<IND ID="T43">
</IND>
This is just returning a null; the parser needs something to tell it that the ID field is the attribute called ID, apparently. The javadocs for XALAN put it this way:
"The DOM implementation must have information that says which attributes are of type ID. Attributes with the name "ID" are not of type ID unless so defined. Implementations that do not know whether attributes are of type ID or not are expected to return null."
So my question is: how do I tell the "DOM implementation" what to use for the ID? And what is the "DOM implementation" anyway? What exactly specifies that?
Thanks - I hope this is the right forum for this.



Reply By: mhkay Reply Date: 11/3/2005 1:40:40 PM
"DOM Implementation" just means the particular product you are using, e.g. Xerces or Oracle, as distinct from the DOM specification.

Typically the implementation knows that your attributes are IDs if the DOM was loaded using a validating parser and the DTD described them as IDs.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply By: Frank Huddleston Reply Date: 11/8/2005 1:55:58 PM
Yes, I suspected that. It seems that the only parser which does schema validation at this point is the commercial SAXON product, so I wrote a DTD, and set the document factory to produce a validating parser. Evidently it did, because I got lots of errors for awhile. But finally it seems the DTD I wrote is passable; however, it still returns a null on the getElementById. Maybe I have not correctly specified the ID element? Here is the top part of the DTD, which contains the ID specification. (I added the "source" attribute so I could track it) Does it look correct?

<!ELEMENT GED  (INDI*, FAM*)>
<!ELEMENT INDI  (REFN, NAME,TITLE?,SEX,CHAN,BIRT,DEAT,NOTE,FAMS+,FAMC)*>
<!ELEMENT FAM (HUSB,WIFE,CHIL+,MARR)*>

<!ATTLIST INDI ID CDATA #REQUIRED>
<!ATTLIST INDI source CDATA #IMPLIED>

<!ATTLIST FAM ID CDATA #REQUIRED>
<!ATTLIST FAM source CDATA #IMPLIED>

Thanks,

Frank Huddleston

Reply By: mhkay Reply Date: 11/8/2005 3:45:57 PM
You've declared the ID attribute as being of type CDATA; you need to declare it as being of type ID.

<!ATTLIST INDI ID ID #REQUIRED>


Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply By: Frank Huddleston Reply Date: 11/11/2005 12:44:32 PM
Thanks; I appreciate the help.


Go to topic 36447

Return to index page 438
Return to index page 437
Return to index page 436
Return to index page 435
Return to index page 434
Return to index page 433
Return to index page 432
Return to index page 431
Return to index page 430
Return to index page 429