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









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
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
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.xmlADS_TO_REPLACE_1 <?xml version="1.0" encoding="UTF-8
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
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
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
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
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
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
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
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
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
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:ADS.../xml/getting-text-values-from-a-nodel.shtml http://www.roseindia.net/xml/dom
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
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
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
validation in struts2 using .xml file
validation in struts2 using .xml file  how to do xml validation in struts2 on dynamic fields   Hello Friend, Please visit the following link:ADS_TO_REPLACE_1 http://www.roseindia.net/struts/struts2/struts2validation
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.xmlADS_TO_REPLACE_1 <?xml version="1.0" encoding="UTF-8
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 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
Reading an XML document using JDOM
Reading an XML document using JDOM   ... by using JDOM.eplace a node with existing node in a DOM document. JDOM is used..., it is a tree based Java api. JDOM represents an XML document as a tree composed
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
XML parsing using Java - XML
XML parsing using Java  I'm trying to parse a big XML file in JAVA..." in element "MIRate"(THE XML code is below).once he enters coverage rate I need... for it skipping all the elements in Table 1. I'm usin using saxparser, startelement
How to generate xml file using xpath
How to generate xml file using xpath  Hi, I have a requirement... to make a xml using that,. It would be great is you can help me out with how to make a xml using xpath. Thanks in Advance, SanjayADS_TO_REPLACE_1   Hi
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
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
Reading a xml file - JSP-Servlet
Reading a xml file  how to read a xml file using jsp and then i have to retrive a data from that file use it in code?  Hi Friend, Please visit the following link: http://www.roseindia.net/jsp/parsing-xml.shtml
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
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
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
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
How I Upload File and Store that file name in Database using JSP
How I Upload File and Store that file name in Database using JSP  Hi All, I m the beginner in JSP and I want to upload the file and store that file... form like Emp name, Emp id, city, address and one employee profile image(upload
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
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
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
Reading a xml file - JSP-Servlet
Reading a xml file  Thanks for ur answer sir but problem is that i have to do a reading a xml file of a employee record and then i have to use a employee details to send mail to those employees how to do i sir please help me
reading data from a text box with the same name using servlets - JSP-Servlet
reading data from a text box with the same name using servlets  Hello sir, i want to get the values from four textboxes having the same name like a= b= c= using servlet i want to print all the values from each text
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
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
Produces XML file but format not correct for storing data using JSP and XML
Produces XML file but format not correct for storing data using JSP and XML  hii I have created a project using JSP and XML as database to store data entered by user in XML file ,It stores data entered in XML file
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
Stored Data in XML File using Servlet
Stored Data in XML File using Servlet  ... to stored data in xml file using Servlet  We have created  file login.jsp... a message 'Xml File Created Successfully'.   JAXP (Java API for XML
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
How to get xml file form http port using web service
How to get xml file form http port using web service  hi I am suresh i am using netbeans 6.9 to develop a web service for getting xml from http port and use the xml data to convert it to java file and store it to DB. But i am
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
Java DOM Tutorial
the elements present in a  XML file using DOM APIs.    To Count...; In this section, you will learn to retrieve all elements of the XML file using the DOM APIs... and using xml files using the standard SAX, DOM and XSLTs.   
Video Tutorial of reading file in Java
get the source code of reading a text file in Java. This source code can... file line by line in Java using Eclipse Project: In this video... Java example for Reading file into byte array Learn how

Ads