I have an XML file which I want to parse(below). I used an example on mykong to learn –
http://www.mkyong.com/java/how-to-read-xml-file-in-java-dom-parser/comment-page-2/#comment-125087
But I got an error “[Fatal Error] flight.xml:3:15: Open quote is expected for attribute “{1}” associated with an element type “id”.”
<?xml version="1.0" encoding="utf-8"?>
<root xmlns:android="www.google.com">
<passenger id=001>
<name>Tom Cruise</name>
</passenger>
<passenger id=002>
<name>Tom Hanks</name>
</passenger>
</root>
I changed the print statements, but it does not work.
System.out.println("Passenger id : " + getTagValue("passenger id", eElement));
System.out.println("Name : " + getTagValue("name", eElement));
How do I edit the code in mykong to make it work for me ?
Update – I made the changes as mentioned below. But, now I don’t see the passenger id’s and names in my output. How do I fix that ?
New XML File here –
<?xml version="1.0" encoding="utf-8"?>
<root xmlns:android="www.google.com">
<passenger id="001">
<name>Tom Cruise</name>
</passenger>
<passenger id="002">
<name>Tom Hanks</name>
</passenger>
</root>
No xml parser will ever accept id=001. It should be either id=”001″ or id=’001′. These are the miminum requirements for a so-called well-formed xml document otherwise it is not an xml document
Besides, make this changes to the code
output