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 3600264
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T20:28:23+00:00 2026-05-18T20:28:23+00:00

Somehow the parsed XML file seems to be wrong or am I doing something

  • 0

Somehow the parsed XML file seems to be wrong or am I doing something wrong?

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<root>
    <quests>
       <quest id="test">
           <question>Just a little sentence.</question>
        </quest>
    </quests>
</root>

I parse it like that:

File file = new File("file.xml");

DocumentBuilderFactory dF = DocumentBuilderFactory.newInstance();
dF.setNamespaceAware(true);
DocumentBuilder dB = dF.newDocumentBuilder();

Document XML = dB.parse(file);

// ------------------------------------------
Element doc = XML.getDocumentElement();
System.out.println(doc.getChildNodes());

Element dx = (Element) doc.getElementsByTagName("quest").item(0);
System.out.println(dx.getAttribute("id"));
System.out.println(dx.getAttribute("id").length());
System.out.println(dx.getAttributes().getLength());

And this is what I get:

[root: null]

0
0

How could that be? How could I parse attributes of elements/tags/nodes?

  • 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-05-18T20:28:23+00:00Added an answer on May 18, 2026 at 8:28 pm

    I just created a new XML file and with that it works!
    I think the problem was maybe an hidden character inside the id
    which causes the error…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Somehow the parsed XML file seems to be wrong or am I doing something
I have the following xml structure : <?xml version=1.0 encoding=utf-8 ?> <nws> <url>http://cpa.hypotheses.org/feed</url> <url>http://news.ycombinator.com/rss</url>
I have an XML file with format similar to: <root> <baby> <a>stuff</a> <b>stuff</b> <c>stuff</c>
Somehow I can't read an XML file with very simple structure in my PowerShell
What happens? I'm guessing that somehow the post or page is parsed before displaying,
I want to parse an XML file with Java and validate it in the
I am trying to parse an XML file using the SAX interface of libxml2
I'm trying to generate an XML file with the my machine's hostname in some
I am currently reading an XML file from a PHP script (as below) which
I have a piece of XML that is structured similar to this: <root> <score

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.