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

  • SEARCH
  • Home
  • 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 6937047
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:18:50+00:00 2026-05-27T12:18:50+00:00

I am trying to open and read a xml file as a local resource

  • 0

I am trying to open and read a xml file as a local resource with jdom. I can open the file but then I got an error saying that the xml file is not well-formed. Here is the code :

Uri path = Uri.parse("android:resource://package_name"+R.xml.data);
InputSource source = new InputSource(new StringReader(path.toString()));
document = builder.build(source);

I got the following error :

org.jdom.input.JDOMParseException:Error on line 1:At line 1, column 17:not well-formed (invalid token)

Here is the xml file with my data:

<?xml version="1.0" encoding="utf-8"?>
<data>
  <person>
    <name>Name1</name>
    <firstname>Firstname1</firstname>
  </person>
  <person>
    <name>Name2</name>
    <firstname>Firstname2</firstname>
  </person>
</data>

Would you have an idea ? Thanks in advance.

  • 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-27T12:18:51+00:00Added an answer on May 27, 2026 at 12:18 pm

    Your InputSource is not reading the resource, it is reading the path to the resource (which is not a well-formed XML file :))

    If you are including an XML resource in Android, it will be pre-parsed at build time, so you don’t want to use JDOM to read it. (If you really want to read it into a DOM, include it as a raw resource)

    Instead, use Resources.getXml(R.xml.data), which will return a XmlPullParser

    If you need it in a DOM, put it with the raw/ resources, and get your reader for your InputSource from openRawResource()

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

Sidebar

Related Questions

I'm trying to save a local copy of an xml file, and then open
i am trying to read the xml file but somehow i am getting this
I want to parse an XML file from URL using JDOM. But when trying
I'm trying to read an xml file into memory, add a node, then write
I'm trying to open a file and create a list with each line read
Trying to read headers for a csv file with: reader = csv.DictReader(open(PATH_FILE),skipinitialspace=True) headers =
I'm currently trying to READ XML file from the client machine where the user
I am trying to parse an xml file using XmlReader but although I am
I'm trying to read in an xml file which looks like this <?xml version=1.0
I'm trying to import an xml file into vb.net XmlDocument but am getting the

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.