Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa XML Reading xml file using dom parser in java with out using getelementby tag name
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


mastanrao
Reading xml file using dom parser in java with out using getelementby tag name
1 Answer(s)      2 years and a month ago
Posted in : XML


Hi, How to read the xml file using java with dom parser, but without using getelementbytag name, and also read the attribute values also.

I had found some thing in the below url : http://www.roseindia.net/answers/viewqa/Java-Beginners/8384-java-with-xml-parsing.html but it is not reading attribute values .

Can any one help me out

Regards PMR


Advertisement
View Answers

June 7, 2013 at 1:58 PM


hi friend,

To read the attribute values you may use the getAttribute() method of Element.

Following code snippet will help you find the attribute value

private static String getTagValue()
    {
NodeList nodeList;
 try
        {
    File xmlfile = new File("Document4.xml");
    DocumentBuilderFactory factory = 
  DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();
              Document doc = builder.parse(xmlfile);
    doc.getElementsByTagName("tagName");
    Element element = (Element) node;
    if (element.getTagName().startsWith("tagName"))
            {
                      return element.getAttribute("attrName");

    }
    else
    {
         return element.getNodeValue();
    }
     }
   catch (Exception exception)
    {
    exception.printStackTrace();
    }

}

Thanks.



Related Tutorials/Questions & Answers:
Reading xml file using dom parser in java with out using getelementby tag name
Reading xml file using dom parser in java with out using getelementby tag name  Hi, How to read the xml file using java with dom parser, but without using getelementbytag name, and also read the attribute values also. I had
Read Complex XML using DOM/SAX Parser.
Read Complex XML using DOM/SAX Parser.  I have a XML file which is having two types of Items. I want to extract all details of a type only. My XML goes something like this <Movie> <Bollywood> <Actor> Shah Rukh
Advertisements
xml file reading using java
xml file reading using java  hi deepak I want to read some data from xml file and send that output to particular email address using java   import org.w3c.dom.*; import org.w3c.dom.Node; import javax.xml.parsers.
Parsing The XML File using DOM parser in JSP
Parsing The XML File using DOM parser in JSP... the DOM (Document Object Model) parser, that is the platform independent... the processing are displayed on to the present page. DOM parser is not an ideal
parsing word xml file using SAX parser - XML
parsing word xml file using SAX parser  i am parsing word 2003's XML file using SAX.here my question is,i want to write some tag elements which are between in other tag to a file. For ex
Java XML Parsing Using DOM
Java XML Parsing Using SAX To Parse XML document using SAX parser method you need to follow the following steps. Consider the following XML file Students.xml <?xml version="1.0" encoding="UTF-8"?> <
Java XML modification
Java XML modification This section explain you how to modify the xml file using DOM parser. For this purpose, you have to use DocumentBuilderFactory, DocumentBuilder and Document classes to get the default DOM parser and parse the xml
Parsing repeatitive xml elements using SAX Parser - XML
SAX Parser to read an XML file. My XML file contains repeatitive tags. I'm... Sehwag Dhoni 35 24 After reading the XML file, i was able to display...)); System.out.print("Enter XML file name:"); String xmlFile
XML Parsing Using Sax Parser in J2ME for serverside
XML Parsing Using Sax Parser in J2ME for serverside  Hai team, i have doubt in Parsing using sax parser in serverside plz help me for xml parsing in j2me using sax parser on server side thanks in advance... regards Selva
Reading RDF file using Java code in Eclipse
Reading RDF file using Java code in Eclipse  Could you please tel me what this statement means - Model model = ModelFactory.createDefaultModel
Insert XML file data to database
Insert XML file data to database In this tutorial, you will learn how to insert the xml file data to database using dom parser. You all are aware of XML file, it is a tag based language. You can easily transfer and store its data
SAX Parser for huge XML file
using dom parser in java. import org.w3c.dom.*; import org.w3c.dom.Node; import...SAX Parser for huge XML file  Hi.... if the XML file is small...("Enter XML file name:"); String xmlFile = bf.readLine(); File file = new File
XML Parsing Using Sax Parser in J2ME
XML Parsing Using Sax Parser in J2ME  Hai team, I hope you, You should help me, I have trouble in Xml parsing... I have decoded value, what my process means to send that value to web services using Get method like
JAXP API using DOM Parser
JAXP API using DOM Parser         Introduction to XML Parser: In computing... and manipulate XML documents using any programming language (and a parser
Reading .doc file using swing
Reading .doc file using swing  Sir, Could U Please Tell me the Way To Read .doc file in java using swing,with code
parser - XML
parser  how to convert XML file to flat file(text file) using DOM and SAX parser
How to Split a large XML file using java?
How to Split a large XML file using java?  How can we split a 500MB Xml file?I know how to split xml file after reading the entire document in a file.Here we cannot load the entire file as it is a large file
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
Java-XML-DOM - XML
Java-XML-DOM  Hi! I need some help. I have to make java program that loads an xml file and from it builds DOM(later i will have to work with it - like using xpath in java find some value and replace it...). Since i'm new to java
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
Java XML Parsing Using SAX
Java XML Parsing Using SAX To Parse XML document using SAX parser method you need to follow the following steps. Consider the following XML file Students.xml <?xml version="1.0" encoding="UTF-8"?> <
parsing xml file using java code
parsing xml file using java code  parsing a xml file using java code
how to read and write an xml file using java
how to read and write an xml file using java  Hi Can anyone help me how to read and write an xml file which has CData using java
Parsing The XML File Using JDOM Parser in JSP
Parsing The XML File Using JDOM Parser in JSP... native parser. XML parsing produces an xml parse tree from an XML document. Using... with JDOM parser to parse the xml document. JDOM can read existing XML documents
Err while reading CSV file using POI - Java Beginners
Err while reading CSV file using POI  Hi, When i am trying to read a CSV file using POI Dile system, the below error is coming up... know, why this is coming up. Is there any other way to read the CSV file. Thanks
accessing xml using java
accessing xml using java  I need to retrieve some elements in xml file using java   Hi Friend, Please visit the following links: http...-text-values-from-a-nodel.shtml http://www.roseindia.net/xml/dom/GetData.shtml
Read XML using Java
of all i need to read xml using java . i did good research in google and came to know.../xmlParsing/java-xml-parsing-using-sax.shtml http://www.roseindia.net/xml/sax... two codes i think reading xml using JDOM is simple. But my XML size ranges from
read XML file and display it using java servlets
read XML file and display it using java servlets  sir, i can't access Xml which is present in my d drive plz can u should go through my code n tell me the things where i went wrong java servlet program protected void
Java DOM Tutorial
file using DOM APIs.    To Count The Elements in a XML File... of the XML file using the DOM APIs. This APIs provides some constructors... through Java. For that we have used DOM parser.   XML Tutorials
download xml file from website using java code
download xml file from website using java code  how to download xml file from website using java code
XML- SAX Parser using JAXP API
XML- SAX Parser using JAXP API           XML- SAX Parser using JAXP API..., you will learn how XML technology works with Java using different kinds of XML
 

 

 

DMCA.com