Note that there are some explanatory texts on larger screens.

plurals
  1. POJava Android: How to read LOCAL Xml file? (Becoming crazy)
    primarykey
    data
    text
    <p>Im becoming crazy attempting to parse a xml file some like this</p> <p>I got it , but reading from a URL of a <strong>REMOTE</strong> XML file </p> <p>There is it, May be helpful for this thread or another </p> <p>LINK TO THE WORKING REMOTE XML PARSING FILE<a href="http://iatek.eu/flagger/new1.java" rel="nofollow">http://iatek.eu/flagger/new1.java</a></p> <p>But I want to read the XML from R.assets/myxml.xml , or something similar, so, as <strong>LOCAL FILE</strong>.</p> <p>Here is a part of the XML that I need to read:</p> <pre><code>&lt;menu&gt; &lt;item&gt; &lt;id&gt;1&lt;/id&gt; &lt;name&gt;Albania&lt;/name&gt; &lt;pop&gt;3.190.000&lt;/pop&gt; &lt;/item&gt; &lt;item&gt; &lt;id&gt;2&lt;/id&gt; &lt;name&gt;Germany&lt;/name&gt; &lt;pop&gt;82.244.000&lt;/pop&gt; &lt;/item&gt; &lt;/menu&gt; </code></pre> <p>So the question is that I need to read data from the same XML file locally and Im starting hating javaa! jaja </p> <p>i have read a lot of stuff about it, ABOUT how the SAX or DOM systems works, bla blah... u have try with a lot of codes and it doesnt work. </p> <p>That is the last attempt </p> <pre><code>public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); try { InputStream in = getResources().openRawResource(R.raw.samp); // Here is the problem ... DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); Document doc = null; NodeList animals = doc.getElementsByTagName("animal"); for (int i=0;i&lt;animals.getLength();i++) { String a=""+((DocumentBuilderFactory) animals.item(i)).getAttribute("species"); } in.close(); doc = builder.parse(in, null); } catch (SAXException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ParserConfigurationException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } </code></pre> <p>But java found errors that I dont understand , So can seomeone help me to read variables from that xml but LOCALLY? thank you, Im desperated i took a lot of time with this without running it</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload