Reading xml file using dom parser in java with out using getelementby tag name

Ads
 

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 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

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.

Ads









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
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.
Advertisements
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
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"?> <
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
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
parsing xml file using java code
parsing xml file using java code  parsing a xml file using java code
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
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
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
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
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
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 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"?> <
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
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
read xml using java
read xml using java  <p>to read multiple attributes and elements from xml in an order.... ex :component name="csl"\layerinterfacefile="poo.c"\interface type=""\level="0"\source_file="ppp" etc as wise each attribute n
Delete and edit data in xml file using JSP
Delete and edit data in xml file using JSP   I want to know how to delete and edit data from an XML file by use of JSP. I have XML file having tasks... in the xml file,I want to delete and edit some tasks using task id then how can i do
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
HOW TO STORE MULTIPLE EMPLOYEE DETAILS TO XML FILE USING JSP?
HELP ME OUT WITH HOW TO VIEW THE STORED DATA IN XML FILE USING EMPNAME. PLEASE...HOW TO STORE MULTIPLE EMPLOYEE DETAILS TO XML FILE USING JSP?  HELLO SIR, CAN ANYONE HELP ME OUT HOW TO STORE MULTIPLE EMPLOYEE DETAILS TO XML
Create XML File using Servlet
Create XML File using Servlet   ... file using Servlet  We have created  file XmlServlet.java. It creates XML file with its version and encoding and display a message 'Xml File Created
reading data using struts and jsp java
reading data using struts and jsp java  how can i read data entered by user into a textbox (jsp page) into struts action class ex emp id,so that after reading emp_id it can be read into struts action class for retrieving other
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
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
xml Converting to java using JDOM
xml Converting to java using JDOM  Hello , I am new to java and JDom so i make a Xml file and i need help to read it from java using objects , my... should be inside a student object i will include the java code and xml code and i
Line by Line reading from a file using Scanner Class
In this section, you will get to know about reading line by line a text file using java.util.Scanner class
Video Tutorial of reading file in Java
performance. Video tutorial for reading a text file line by line in Java using... the source code of reading a text file in Java. This source code can be run in Eclipse... Read File in Java Java example for Reading file into byte
Interceptors Configuration using Java or XML
In this section, you will learn about how to configure interceptors using Java or XML
How to handle Transaction IN and OUT in Inventory using java
How to handle Transaction IN and OUT in Inventory using java  Hi.... The scanned data is in .CSV file, Loaded to Oracle database using Oracle SQL Developer...,TransactionStatus, Dt.of.Transaction, when i load the .CSV file to this table
tag name in xml
tag name in xml  How to get tag name in xml?   <?xml...="http://www.w3.org/1999/XSL/Transform"> <xsl:variable name="outermostElementName" select="name(/*)" /> <xsl:template match="/"> <xsl

Ads