xml parsing problem

Common bugs/problems with the Android SDK the Emulator and the ADT-Plugin.

xml parsing problem

Postby morshed1471 » Sun May 31, 2009 5:22 pm

Dear Friends,
I am facing parsing problem using Tag "lgCommon:entityDescription". I want to parse information using tag and store it some where .
Could you please suggest me how can I solve the problem.

import java.io.File;

import java.io.IOException;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;

public class CabiParser {
public static void main(String[] args) throws ParserConfigurationException, SAXException, IOException {
DocumentBuilderFactory dbfactory = DocumentBuilderFactory.newInstance();
DocumentBuilder domparser = dbfactory.newDocumentBuilder();

//parse the XML and create the DOM
Document doc = domparser.parse(new File("C:/matchdata/agrotest.xml"));

NodeList nl = doc.getElementsByTagName("lgCommon:entityDescription");
for (int i = 0; i < nl.getLength(); i++) {
Node n = nl.item(i);
String str = n.getTextContent();
System.out.println("String of concept" +str);
//NodeList nl= doc.getChildNodes();
// printElementAttributes(doc);
// printElements(doc);


my file structure are following:
<?xml version="1.0"?>
<concept conceptCode="201" conceptStatus="">
<lgCommon:entityDescription>Agricultural policies</lgCommon:entityDescription>
<presentation property="textualPresentation" propertyId="201-EN" isPreferred="true" language="EN">
<text>Agricultural policies</text>
<presentation property="textualPresentation" propertyId="201-AR" isPreferred="true" language="AR">
<text>????? ??????</text>
<presentation property="textualPresentation" propertyId="201-ZH" isPreferred="true" language="ZH">
<presentation property="textualPresentation" propertyId="201-FR" isPreferred="true" language="FR">
<text>Politique agricole</text>
<presentation property="textualPresentation" propertyId="201-ES" isPreferred="true" language="ES">
<text>Política agrícola</text>
<presentation property="textualPresentation" propertyId="201-CS" isPreferred="true" language="CS">
<text>zemìdìlská politika</text>
<presentation property="textualPresentation" propertyId="201-PT" isPreferred="true" language="PT">
<text>Política agrícola</text>
<presentation property="textualPresentation" propertyId="201-JA" isPreferred="true" language="JA">

I am interested on java programming , spring, web application.
Once Poster
Once Poster
Posts: 1
Joined: Sun May 31, 2009 5:07 pm


Re: xml parsing problem

Postby hPushpa18 » Fri Nov 06, 2009 6:13 am


Are u able to successfully extract the data from xml?If yes can u plz attach ur project(entire source code) and send it to me plz i really need it urgently as i als have to do xml parsing.

Thanks and Regards,
Junior Developer
Junior Developer
Posts: 14
Joined: Mon Nov 02, 2009 11:08 am
Location: Bangalore

Postby rogerdodger » Wed Dec 02, 2009 11:16 pm

will this work for a remote xml file, like this

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  2. //parse the XML and create the DOM
  4. Document doc = domparser.parse(new File("http://myDomain.com/agrotest.xml"));
Parsed in 0.031 seconds, using GeSHi

This looks way faster than the sax parser. Why is the sax parser so long and cumbersome???
Junior Developer
Junior Developer
Posts: 21
Joined: Mon Nov 30, 2009 8:38 am

Postby shishir.bobby » Tue Feb 23, 2010 11:14 am

or u can try this

static String feedUrl = "http://www.androidster.com/android_news.rss";

public static FeedParser getParser(){
return getParser(ParserType.ANDROID_SAX);

public static FeedParser getParser(ParserType type){
switch (type){
case SAX:
return new SaxFeedParser(feedUrl);
case DOM:
return new DomFeedParser(feedUrl);
return new AndroidSaxFeedParser(feedUrl);
case XML_PULL:
return new XmlPullFeedParser(feedUrl);
default: return null;


Try above.

my problem is,how can i call my local xml file??
i want to parse sml,can any 1 show me a smalll example

Thanks And Regards
Experienced Developer
Experienced Developer
Posts: 76
Joined: Thu Apr 09, 2009 11:41 am

xml parsing problem

Postby vengence » Sat Feb 27, 2010 4:27 am

Using SAX is somewhat slow and outdated ... Have you look at pull parsing, or VTD-XML (http://vtd-xml.sf.net)?
Once Poster
Once Poster
Posts: 1
Joined: Sat Feb 27, 2010 4:21 am

Postby shishir.bobby » Sat Feb 27, 2010 5:43 am

hey thankx for quick reply..

i never worked before on SAX ,pull parsing, or VTD-XML..

if u can proivide me a demo ,how to call xml in android, particularly showing it in activity or through through main.xml .

Thankx again

Experienced Developer
Experienced Developer
Posts: 76
Joined: Thu Apr 09, 2009 11:41 am


Return to SDK/ADT/Emulator Problems

Who is online

Users browsing this forum: No registered users and 4 guests