Note that there are some explanatory texts on larger screens.

plurals
  1. POmy xml parser(SAX parser) parses only URI source. How can I parse a file which exists in my project with SAXparser?
    primarykey
    data
    text
    <p>This is the code which can only parse URI sources.</p> <pre><code> package com.example.xmlparserdeneme; import java.io.IOException; import java.util.ArrayList; import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; import org.xml.sax.Attributes; import org.xml.sax.SAXException; import org.xml.sax.helpers.DefaultHandler; import android.app.Activity; import android.content.Context; import android.os.AsyncTask; import android.os.Bundle; import android.util.Log; import android.view.Menu; import android.widget.ListView; public class MainActivity extends Activity { ArrayList&lt;String&gt; titles = new ArrayList&lt;String&gt;(); Context ctx = this; CustomAdapter adapter = null; ListView lv; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ctx = this; new parseXML().execute(); Log.i("info2", titles.toString()); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } class parseXML extends AsyncTask&lt;String, Void, String&gt; { MySaxHandler handler; @Override protected String doInBackground(String... params) { // ((Activity) ctx).setContentView(R.layout.activity_main); SAXParserFactory spf = SAXParserFactory.newInstance(); SAXParser parser = null; try { parser = spf.newSAXParser(); } catch (ParserConfigurationException e) { e.printStackTrace(); } catch (SAXException e) { e.printStackTrace(); } handler = new MySaxHandler(); try { parser.parse("http://sosyalmedya.co/mobile-feed/", handler); // parser.parse("file:///android_asset/DirenisDB.txt", handler); } catch (SAXException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } Log.i("info", titles.toString()); // Toast.makeText(ctx, "POST", Toast.LENGTH_LONG).show(); // setAdapter(); return "a"; } @Override protected void onPostExecute(String result) { lv = (ListView) findViewById(R.id.listView); lv.setAdapter(new CustomAdapter(titles, ctx)); } public ArrayList&lt;String&gt; getArray() { return titles; } public class MySaxHandler extends DefaultHandler { StringBuffer chars; public void startElement(String uri, String localName, String qName, Attributes atts) { chars = new StringBuffer(); } public void endElement(String uri, String localName, String qName) throws SAXException { if (localName.equalsIgnoreCase("key")) titles.add(chars.toString()); } public void characters(char ch[], int start, int length) { chars.append(new String(ch, start, length)); } } } } </code></pre> <p>I've spent almost 6 hours on it but I still couldn't figure it out. I just want it to parse this(a file)<code> parser.parse("file:///android_asset/DirenisDB.txt", handler);</code> instead of this(URI) <code>parser.parse("http://sosyalmedya.co/mobile-feed/", handler); </code>.</p> <p>I'd be appreciated if you can solve my problem.</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.
 

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