Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

XML : getElementById returns null

 
John Landon
Ranch Hand
Posts: 228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
If you look here:
api/org/w3c/dom/Document.html#getElementById(java.lang.String)
It says : "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 how do I "define so.."?

Because the only reason it returns null is because of this. My document has only 1 node with attribute ID = "the name".

Thanks.
[ December 09, 2008: Message edited by: John Landon ]
 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have to create a schema, or a DTD, which declares that "id" attribute to be of ID type. (Sorry, I don't know how to do that.) And when parsing the document, you have to make sure you validate it against that schema or DTD.

If that seems like a lot of trouble you could just replace that code by a call to something that applies the equivalent XPath expression.
 
Matthias Wiels
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
At http://java.sun.com/j2se/1.5.0/docs/api/org/w3c/dom/Attr.html#isId() you find another method.

From the use of the methods Element.setIdAttribute(), Element.setIdAttributeNS(), or Element.setIdAttributeNode()
 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's an interesting point. I haven't seen that method before. Have you gone so far as to see if it actually solves John's problem?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic