Note that there are some explanatory texts on larger screens.

plurals
  1. POStandard Xml parser in android
    primarykey
    data
    text
    <p>Is there a standard xml parser in android, where i can put any standard link for the RSS and it will give me the result? i found an example but i must specify the path for the items. Some thing like this link <a href="http://www.rssboard.org/files/sample-rss-2.xml" rel="nofollow">http://www.rssboard.org/files/sample-rss-2.xml</a></p> <pre><code> try { URL conn = new URL("http://www.rssboard.org/files/sample-rss-2.xml"); XmlParserHelper helper = new XmlParserHelper(conn.openStream(), "rss"); final String TITLES = "language"; XmlParseObject object = helper.createObject(TITLES, "//channel//item//title"); object.setParseAttributes(); object.setParseContent(); Map&lt;String, List&lt;XmlObject&gt;&gt; results = helper.parse(); List&lt;XmlObject&gt; titlesList = results.get(TITLES); for (XmlObject title : titlesList) { Log.d("Guid:", title.toString()); } } catch (Exception e) { e.printStackTrace(); } public class XmlParserHelper { protected String mRootName = ""; protected InputStream mXmlStream = null; protected List&lt;XmlParseObject&gt; mParseList = new ArrayList&lt;XmlParseObject&gt;(); /** * Initialize xml helper with file stream * @param xmlStream input xml stream */ public XmlParserHelper(InputStream xmlStream, String rootName) { this.mXmlStream = xmlStream; this.mRootName = rootName; } /** * Point parse all attributes for XPath * @param objectName key for attributes list in response * @param XPath path to tag */ public void createAttributesObject(String objectName, String XPath) { XmlParseObject currentObject = new XmlParseObject(objectName, XPath); currentObject.setParseAttributes(); mParseList.add(currentObject); } public void createContentObject(String objectName, String XPath) { XmlParseObject currentObject = new XmlParseObject(objectName, XPath); currentObject.setParseContent(); mParseList.add(currentObject); } public XmlParseObject createObject(String objectName, String XPath) { XmlParseObject currentObject = new XmlParseObject(objectName, XPath); mParseList.add(currentObject); return currentObject; } public Map&lt;String, List&lt;XmlObject&gt;&gt; parse() throws Exception { if (mRootName.equals("")) { throw new Exception("Root tag must be defined"); } RootElement root = new RootElement(mRootName); for (XmlParseObject parselable : mParseList) { parselable.configurateListenersForRoot(root); } try { Xml.parse(mXmlStream, Xml.Encoding.UTF_8, root.getContentHandler()); } catch (Exception e) { e.printStackTrace(); throw new RuntimeException(e); } Map&lt;String, List&lt;XmlObject&gt;&gt; result = new HashMap&lt;String, List&lt;XmlObject&gt;&gt;(); for (XmlParseObject parselable : mParseList) { result.put(parselable.getName(), parselable.getResults()); } return result; } </code></pre> <p>}</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.
 

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