This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes XML and Related Technologies and the fly likes XML : getElementById returns null Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "XML : getElementById returns null" Watch "XML : getElementById returns null" New topic

XML : getElementById returns null

John Landon
Ranch Hand

Joined: Sep 25, 2008
Posts: 228
If you look here:
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".

[ December 09, 2008: Message edited by: John Landon ]
Paul Clapham

Joined: Oct 14, 2005
Posts: 19851

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

Joined: Dec 21, 2008
Posts: 1
At you find another method.

From the use of the methods Element.setIdAttribute(), Element.setIdAttributeNS(), or Element.setIdAttributeNode()
Paul Clapham

Joined: Oct 14, 2005
Posts: 19851

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?
Consider Paul's rocket mass heater.
subject: XML : getElementById returns null
It's not a secret anymore!