Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8957737
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:03:35+00:00 2026-06-15T15:03:35+00:00

I have an XML file which I want to parse(below). I used an example

  • 0

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>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T15:03:36+00:00Added an answer on June 15, 2026 at 3:03 pm

    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

    •XML documents must have a root element
    •XML elements must have a closing tag
    •XML tags are case sensitive
    •XML elements must be properly nested
    •XML attribute values must be quoted
    

    Besides, make this changes to the code

    public static void main(String argv[]) throws Exception {
        File fXmlFile = new File("c://file.xml");
        DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
        Document doc = dBuilder.parse(fXmlFile);
        doc.getDocumentElement().normalize();
        System.out.println("Root element :" + doc.getDocumentElement().getNodeName());
        NodeList nList = doc.getElementsByTagName("passenger");
        System.out.println("-----------------------");
        for (int temp = 0; temp < nList.getLength(); temp++) {
            Node nNode = nList.item(temp);
            if (nNode.getNodeType() == Node.ELEMENT_NODE) {
                System.out.println("Passenger id : " + e.getAttribute("id"));
                System.out.println("Name : " + e.getElementsByTagName("name").item(0).getTextContent());
            }
        }
    }
    

    output

    Root element :root
    -----------------------
    Passenger id : 001
    Name : Tom Cruise
    Passenger id : 002
    Name : Tom Hanks
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i want parse xml file, which does't have xml extension, like this: http://bizonek.wrzuta.pl/xml/plik/1ANdXCgTOit/unknow/undefined/643/ my
I have an XML file which is as follows. I want to parse this
I have a XML-file, which contains the data of a calendar. I want to
I have an XML file which I need to parse using PHP and send
I have an XML file which has many section like the one below: <Operations>
I have an XML file which I'd like to parse into a non-XML (text)
I have a xml file which contains arabic characters.When i try to parse a
I have a xml URL file in which there are white spaces i want
I have a big (1.9 GB) XML file which has data I want to
I'm using XML::Simple to parse an XML file which I then want to use

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.