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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:04:46+00:00 2026-05-23T08:04:46+00:00

In non-Android java, I used to use: DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder =

  • 0

In non-Android java, I used to use:

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();

File file = new File("res/xml/xml_sample.xml");
Document document = builder.parse(file);

Now in Android the xml seems to get into R.xml.xml_parse, at least it’s defined into the R.java file. However, I can’t seem to access that path to use it as the File constructor argument.

I’ve seen multiple solutions around which involve using getResources() like this one:

http://blog.dimond.de/?p=35

However, since this code is in a independent class which is not an Activity, it doesn’t work.

Any help is appreciated.

  • 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-23T08:04:46+00:00Added an answer on May 23, 2026 at 8:04 am

    I think the other answers are ignoring that you want to use this XML (in a DOM) in non-Android specific code.

    If you put the XML under res/xml, you can only use the XML pull parser on it, not the DOM parser. Usually that’s what you want, and it’s a lot more efficient, since most of the actual work of parsing is done at .apk build time; but if you need to use a DOM parser, put the XML file in res/raw. You can get an InputStream from a raw resource like this:

    InputStream is = getResources().openRawResource(R.raw.hello)
    

    and pass the input stream (instead of any kind of File or path) to the DOM parser.

    Your other option is to use the pull parser events to build the DOM object, and then use that.

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

Sidebar

Related Questions

More specifically, is it possible for an non-android Java application to use android's speech
I see a lot of java code where android prefers to have developers use
I'm using Eclipse to learn to develop Android applications in Java. I haven't used
How to parse non well-formed HTML in android ? I tried to use XOM
Non inline function defined in header file with guards #if !defined(HEADER_RANDOM_H) #define HEADER_RANDOM_H void
I have a non-.Net executable file that is included in my .net assembly as
Here is my code for my db class: package one.two; import java.util.List; import android.app.ListActivity;
I have been slowing learning and building my first android app. I'm VERY new
I'm moving a project to the new Android Native Development Kit (i.e. JNI) and
I am confused about when to use primitive vs. non-primitive(?) types (i.e. int vs.

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.