Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XML
| Search | Today's Posts | Mark Forums Read
XML General XML discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XML section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old November 3rd, 2005, 01:27 PM
Registered User
 
Join Date: Nov 2005
Location: San Antonio, Texas, .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Using getElementById

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.



  #2 (permalink)  
Old November 3rd, 2005, 02:40 PM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

"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
  #3 (permalink)  
Old November 8th, 2005, 02:55 PM
Registered User
 
Join Date: Nov 2005
Location: San Antonio, Texas, .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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?,************,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

  #4 (permalink)  
Old November 8th, 2005, 04:45 PM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

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
  #5 (permalink)  
Old November 11th, 2005, 01:44 PM
Registered User
 
Join Date: Nov 2005
Location: San Antonio, Texas, .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks; I appreciate the help.



Similar Threads
Thread Thread Starter Forum Replies Last Post
Using typeOf with getElementById() atcs2152 Javascript 2 December 16th, 2005 08:19 AM
Why getElementById("f2").style vinod_yadav1919 Javascript How-To 2 January 18th, 2005 11:00 AM
getElementByID error lian_a Javascript How-To 1 December 21st, 2004 01:42 AM
'getElementById()' anshul Javascript How-To 1 September 1st, 2004 03:57 PM
document.getElementById(). PKC XSLT 0 July 21st, 2004 02:11 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.