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();
dbfactory.setNamespaceAware(true);
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);
}
}[syntax="xml"]
my file structure are following:
<?xml version="1.0"?>
<agrovocthesaurus>
<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>
<presentation property="textualPresentation" propertyId="201-AR" isPreferred="true" language="AR">
<text>????? ??????</text>
</presentation>
<presentation property="textualPresentation" propertyId="201-ZH" isPreferred="true" language="ZH">
<text>????</text>
</presentation>
<presentation property="textualPresentation" propertyId="201-FR" isPreferred="true" language="FR">
<text>Politique agricole</text>
</presentation>
<presentation property="textualPresentation" propertyId="201-ES" isPreferred="true" language="ES">
<text>Política agrícola</text>
</presentation>
<presentation property="textualPresentation" propertyId="201-CS" isPreferred="true" language="CS">
<text>zemìdìlská politika</text>
</presentation>
<presentation property="textualPresentation" propertyId="201-PT" isPreferred="true" language="PT">
<text>Política agrícola</text>
</presentation>
<presentation property="textualPresentation" propertyId="201-JA" isPreferred="true" language="JA">
<text>???????</text>
</presentation>
</concept>
</agrovocthesaurus>




