Dom xml parsing in android
I don't understand why people are asking this question here without searching the net properly. Please remember this web search before asking for anything here. Below is the link where you can find a very good xml parsing tutorial ...
http://www.androidpeople.com/android-xml-parsing-tutorial-%E2%80%93-using-domparser
source to share
My suggestion starts with a basic step:
- think about your connection to the xml: url file? local?
- DocumentBuilderFactory instance and builder
DocumentBuilder dBuilder =. DocumentBuilderFactory.newInstance () newDocumentBuilder ();
OR
URLConnection conn = new url (url) .openConnection (),
InputStream inputXml = conn.getInputStream ();DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance () .newDocumentBuilder (); XmlDoc = docBuilder.parse (inputXml);
XML file parsing:
XmlDom document = dBuilder.parse (xmlFile);
After that, it turns the xml file into a DOM or Tree structure and you need to move node to node. In your case, you need to get content. Here's an example:
String getContent(Document doc, String tagName){
String result = "";
NodeList nList = doc.getElementsByTagName(tagName);
if(nList.getLength()>0){
Element eElement = (Element)nList.item(0);
String ranking = eElement.getTextContent();
if(!"".equals(ranking)){
result = String.valueOf(ranking);
}
}
return result;
}
The return of getContent (xmlDom, "MediaTitle") is "hiiii".
Good luck!
source to share