I tried making a java based SAX parser for my XML file. I altered the code in this example.
I also posted this question on stack overflow, but none of the responses could solve my problem.
The problem is that I do not see passenger id value in the output. But, I see passenger printed. How do I fix this ?
Java Newbie with 72% in OCJP/SCJP - Super Confused Jobless Programmer.
I am a "newbie" too. Please verify my answers before you accept them.
You might want to go back to your XML book and read a bit more about the basic parts of an XML document. This fragment here:
is the start tag of a "passenger" element. It contains an "id" attribute whose value is "001". If you interpreted it as an element whose name was "passenger id", then that wasn't correct. An XML element name can't contain whitespace.
It isn't illegal to put whitespace around the equal sign in an attribute, but almost nobody ever does that. Typically the tag would look like this:
That would make it a little more difficult for the unwary reader to mistake the meaning of the tag.
And by the way you shouldn't be using "equalsIgnoreCase" to compare an element name. In XML, element names are case-sensitive so "passenger" and "Passenger" are different things.