good morning friends....................
Java XML getElementById returning null, fix using XPath
I had almost lost my breath over this issue for an entire day and found that the solutions provided in most blogs and forums doesn't for a tight schedule.
Here, I am sharing the method that finally worked for me. I am using Netbeans with the default DOM parser(SAX Parser) provided in javax package.
The problem is that the method:
Document.getElementById(String id)
returns null unless we explicitly specify the type of an attribute as ID.
The Javadoc for this method 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."
The type of attributes can be defined in two ways, either by using a DTD or xml schema.
But, because I was really in short of time, I didn't want to go through all the complexities of implementing a DTD or XSD validation. Trust me…
Comments
Post a Comment