Srikanth
parse xml
1 Answer(s)      9 months ago
Posted in : Java Beginners

<STATES>

<STATE sname="AndhraPradesh" >
    <DISTRICT dname="Ananthapur" >
        <address>
            Apollo Pharmacy, ANANTHAPUR (0.0 km)
            D.NO.15/545, NEAR SAPTHAGIRI CIRCLE ANANTHAPUR, Rayalaseema, ANANTHAPUR, ANATHAPUR , ANDHRA PRADESH
        </address>
    </DISTRICT>

    <DISTRICT dname="Kurnool" >
        <address>
            Apollo Pharmacy, KURNOOL (0.0 km)
            municipal no. D No: 46/697-A, Budwarpeta, KURNOOL, KURNOOL, ANDHRA PRADESH
        </address>
        <address>
            Apollo Pharmacy, KURNOOL 2 (0.0 km)
            1-155, Rayalaseema, KURNOOL 2, KURNOOL, ANDHRA PRADESH
        </address>
    </DISTRICT>

    <DISTRICT dname="EastGodawari" >

        <address>
            Apollo Pharmacy, VENKATESWAR COLONY (MAHABUB NAGAR) (0.0 km)
            D.No.7-4-58/A, Main Road Opp:A.P.S.E.B.Buliding, Mahabub, VENKATESWAR COLONY (MAHABUB NAGAR), HYDERABAD, ANDRA PRADESH
        </address>
        <address>
            Apollo Pharmacy, MAHABOOBNAGAR (0.0 km)
            1-5-35/6, Beside Andhrabank ATM, Mahaboobnagar, Telangana, MAHABOOBNAGAR, HYDERABAD, ANDHRA PRADESH
        </address>
        <address>
            Apollo Pharmacy, METTUGUDA - MAHABOOBANAGAR - 2 (0.0 km)
            1-4-30/D/B, Mahaboobnagar, METTUGUDA - MAHABOOBANAGAR - 2, HYDERABAD, ANDHRA PRADESH
        </address>
    </DISTRICT>

</STATE>

 <STATE sname="AndhraPradesh1111" >
    <DISTRICT dname="Ananthapur1111" >
        <address>
            Apollo Pharmacy, ANANTHAPUR (0.0 km)
        </address>
    </DISTRICT>

    <DISTRICT dname="Kurnool1111" >
        <address>
            Apollo Pharmacy, KURNOOL (0.0 km)
        </address>
        <address>
            Apollo Pharmacy, KURNOOL 2 (0.0 km)
        </address>
    </DISTRICT>

    <DISTRICT dname="EastGodawari1111" >

        <address>
            Apollo Pharmacy, VENKATESWAR COLONY (MAHABUB NAGAR) (0.0 km)
        </address>
        <address>
            Apollo Pharmacy, MAHABOOBNAGAR (0.0 km)
        </address>
        <address>
            Apollo Pharmacy, METTUGUDA - MAHABOOBANAGAR - 2 (0.0 km)
        </address>
    </DISTRICT>

</STATE>

How to parse the above xml. please help me

View Answers

July 31, 2012 at 5:37 PM


Here is a code that parses an xml file using DOM Parser.

import org.w3c.dom.*;
import org.w3c.dom.Node;
import javax.xml.parsers.*;
public class ParseXML{
    public static boolean isTextNode(Node n){
    return n.getNodeName().equals("#text");
  }
    public static void main(String[]args)throws Exception{
  DocumentBuilderFactory docFactory =  DocumentBuilderFactory.newInstance();
  DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
  Document doc = docBuilder.parse("c:/file.xml");

          Element  element = doc.getDocumentElement(); 
          NodeList personNodes = element.getChildNodes();     
          for(int i=0; i<personNodes.getLength(); i++){
            Node emp = personNodes.item(i);
            if(isTextNode(emp))
            continue;
            NodeList nlist = emp.getChildNodes(); 

            for(int j=0; j<nlist.getLength(); j++ ){
            Node node = nlist.item(j);

            if(isTextNode(node)) 
              continue;

            System.out.print(node.getFirstChild().getNodeValue()+"\t ");
          } 
          System.out.println();
        }
    }
}









Related Pages:
parse xml
; </STATE> How to parse the above xml. please help me   Here is a code that parses an xml file using DOM Parser. import org.w3c.dom.*; import...parse xml   <STATES> <STATE sname="AndhraPradesh" >
how to parse xml in j2me tutorial
how to parse xml in j2me tutorial   i want to parse xml file in j2me wireless toolkit.i saw ur examples & source code for parsing xml file in j2me & i try to execute same example on my pc i some how manage to run
Java code to parse xml - Java Beginners
/GetData.shtml The example explains how to parse a xml document. Thanks...Java code to parse xml   TL1 10.50.26.98... to parse the code and get the values from
php parse soap response
php parse soap response  What is soap and how can i convert a soap response to XML. Thanks in Advance
How to parse an XML as per dtd in java
How to parse an XML as per dtd in java  Please help to tell me a logic to parse an xml as per mentioned dtd inside xml. I've used SAX and DOM both but that only check for well formed xml tags but don't validate as per DTD. please
How to parse the attributes from XML using KXML parser in j2me
How to parse the attributes from XML using KXML parser in j2me  Dear Sir, I have doubt in How to parse the attributes from XML using KXML parser in j2me ..I parse the dge name value..but i didn't do parsing the attributes
Could not parse configuration: hibernate.cfg.xml
Could not parse configuration: hibernate.cfg.xml  Hi, I am getting.... Exception in thread "main" org.hibernate.HibernateException: Could not parse...(Configuration.java:1532) ... 2 more hibernate.cfg.xml file- <?xml
How to parse the attributes values from XML using KXML parser in j2me
How to parse the attributes values from XML using KXML parser in j2me  hai team, i did xml parsing from serverside...i got a resultant value from xml,but here tag value name only came from parsing attribute name cant come
Use of <x:parse> tag of JSTL
:parse> tag of  Xml tag library of Jstl. This tag is used to parse the specified xml document. Standard Syntax : <%@ taglib prefix="x" uri="... xml content. varDom  This is variable name
how to parse xml document which contains elements with namespace using JDOM - XML
how to parse xml document which contains elements with namespace using JDOM  Hello, I am parsing XML file ,which has structure like... is inside so how can i parse this xml using JDOM,java. Thanks Shree  Hi
xml - XML
xml  define parser and xml,in jaxp api how to up load parsers... it into identifiable chunks before translation. If the parser cannot parse a program then the program contains syntax errors. XML is defined as an extensible
xml - XML
xml  hi convert xml document to xml string.i am using below code... = documentBuilderFactory.newDocumentBuilder().parse(inputStream); StringWriter stw = new... = stw.toString(); after i am getting xml string result, like Successxxx profile
DOM Parser Example to Parse A DOM Document
DOM Parser Example to Parse A DOM Document In this tutorial, we will discuss about how to parse(retrieve data) DOM Document. The XML DOM views an XML document as a tree-structure. In this program, we read the XML file and print
xml or database - XML
xml or database  If I implement some web applications, which is a better way to retrieve and parse xml file directly using DOM or storing those xml files in Database and retrieve. My xml files will be about 100 - 200 and each
xml parsing - XML
xml parsing  Hi i want to parse the xml document which contains US en tages but the values of the tags are in differet language for ex greek...± how can i do this?   Hi friend, Parsing The XML File using DOM
Use of Core XML tags in JSP
Tags: Core XML tags provides access to XML data and used to parse these data... is used to parse an XML document and it saves the resulting object into an EL..." />   <x:parse xml="${user}" var="doc" />   
Java APIs for XML Processing (JAXP)
Java APIs for XML Processing (JAXP)       JAXP (Java APIs for XML Processing) enables applications to parse, transform, validate and query XML documents using API. This API
Java APIs for XML Processing (JAXP)
Java APIs for XML Processing (JAXP)       JAXP (Java APIs for XML Processing) enables applications to parse, transform, validate and query XML documents using API. This API
XML Expat Library:
XML parser is based on Expat. It lets you parse but not validate XML... language</Java></lang>"; $parse=xml_parser_create(); xml_parse_into_struct($parse,$xml,$var1,$var2); xml_parser_free($parse
parsing xml with jquery
parsing xml with jquery  Please explain how to parse a xml file into jquery. Thanks
readXML - XML
u parse. Thanks'' Rajanikant   just check ur xml file it is wrong...readXML  hiii i face problems in reading a xml file.... This link will help you. Please visit : http://www.roseindia.net/xml
parse in iphone
parse in iphone  <p>{ itemCount: 2, subtotal: "$15.50", items:[ { title: "The Big Book of Foo", description: "Bestselling book of Foo by A.N. Other", imageUrl: "/images/books/12345.gif
XML and swings - Java Beginners
XML and swings  I have an xml file where all the contents that should be present in the tabbed pane are there. i would like to know how to parse the xml such that, whenever it reads the component type as label, it should create
XML parsing using Java - XML
XML parsing using Java  I'm trying to parse a big XML file in JAVA. The goal is like i will take console input from user until "Coverage" in element "MIRate"(THE XML code is below).once he enters coverage rate I need
Java XML Parsing Using SAX
Java XML Parsing Using SAX To Parse XML document using SAX parser method you... = saxParserFactory.newSAXParser(); // Parsing XML Document by calling parse method... = saxParserFactory.newSAXParser(); // Parsing XML Document by calling parse method of SAXParser
Java XML Parsing Using DOM
Java XML Parsing Using SAX To Parse XML document using SAX parser method you... = saxParserFactory.newSAXParser(); // Parsing XML Document by calling parse method... = saxParserFactory.newSAXParser(); // Parsing XML Document by calling parse method of SAXParser
xml document parsing
xml document parsing   Hi Guys, Xml document has been inserted into the database,how do i parse the xml document stored in database,so that xml document can be retrieved on to JSP file using jdbc/odbc connection. Please help me
php parse ini string
php parse ini string  Need to know how to parse the ini file to extract values
php parse string for url
php parse string for url  Do i need a regex to parse a URL-type string in PHP
php parse string into array
php parse string into array  How can i parse a string into array and convert an array into string
php parse string to time
php parse string to time  I am looking for a solution to parse a string into a formatted date time string
parse url iphone sdk
parse url iphone sdk  How can i parse two different URL's using NSXMLParser
parse map in java
parse map in java  What is a Parser? Can you give the source code to parse map in Java
XML Schema
schema 12 Xml Parser can be used to parse the schema file 13...: #FFFFFF; } XML Schema An XML Schema defines how to structure an XML document and it can be used in place of DTD. XML Schema is based on XML. XML Schema
php parse ini array
php parse ini array  I wanted to parse a variable inside a variable value. Can any one give the example
Retrieving Data From the XML file
:\apache-tomat-5.5.23\bin\. Now we need to parse method to actually parse the XML file... Retrieving Data From the XML file       In this example we will examine how to parse
complex xml parsing and storing in database - XML
complex xml parsing and storing in database  Hi Experts ,i want to parse my xml document and store it in mysql database. This is my code. How to parse this complex data. EDI_DC40 800 0000000000557748
php parse string as php
php parse string as php  Best way of parsing a string within a string
php parse ini file
php parse ini file  I need a simple and easy example to Parsing an ?advanced? INI file with PHP
php parse string to float
php parse string to float  Is there any Regex or way to get float from a string
XML Parsers
for that language). This standard API works in serial access  mode to parse XML... XML Parsers       XML parser is used to read, update, create and manipulate an XML document. Parsing
XML and JavaScript
JavaScript and XML In this section we will see how JavaScript and XML... libraries to fetch the server data. Developer can use these XML data or JSON data retrieved from the server. Here XML plays important role data transfer
php parse subdomain
php parse subdomain  Basically, looking for a example on how to let PHP to create subdomain automatically for each user? Is it possible to retrieve subdomain as a get variable
Why XML?, Why XML is used for?
API is used by the programmers to parse the data stored in XML file. XML parsers...Why XML? In this section we will understand the importance of XML and see Why XML is so important these days. We will also see the different usages of XML
php parse string as int
php parse string as int  While trying to pass string to int using int() i get the following error: Call to undefined function int() Why it is throwing an error
php parse string to date
php parse string to date  In my app i have a date string in the following format: $date = "08/20/2009"; Can you suggest how can i separate each part of the date
date_parse
date_parse() in PHP date_parse function returns associative array... error. Description on Date Parse Format in PHP array date_parse ( string $date ) Parameters of date parse class PHP date - Date in format accepted
Parsing XML using Document Builder factory - XML
Parsing XML using Document Builder factory  Hi , I am new to XML . I am trying to parse a XML file while is : For this i am using Document builder factory parser . This is required inside a STAX job.The development env
parsing XML file to get java object - XML
parsing XML file to get java object  Hello, I'm facing a problem in parsing XML file to get the java object. I've tried to retrieve data from XML file using SAX parser. my XML file structure is the following
KXML Parse Example
; This is the XML connection example. In this section, we'll develop a J2ME application that a user can connect to the xml file from localhost and print...; AddressBook is a simple XML format that summarizes name and address tags. when

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.