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

Have Programming Question? Ask it here!
 
 
 


mastanrao
Reading xml file using dom parser in java with out using getelementby tag name
1 Answer(s)      a year and 11 months 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
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 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
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
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
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
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
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 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
Java XML parser
Java XML parser  Hi friends, i am new to java XML parsing. i need to parse the following xml response which i got from a url hit: <response> <status>SUCCESS</status> <app-config> <CHECK_LOW_SCORE>
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
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
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: http://www.roseindia.net/struts/struts2/struts2validation.shtml Thanks
XML DOM error - Java Beginners
XML DOM error  import org.w3c.dom.*; import javax.xml.parsers.... InputStreamReader(System.in)); System.out.print("Enter File name... by specifying the file name in the code like: String xmlFile = "C:\\data.xml"; If you
XML Error checker and locater (DOM)
and locate (line and column number) an error in your XML document using the DOM APIs... C:\vinod\xml>java DOMLocateError Enter File name... XML Error checker and locater (DOM)   
Xml Parser
Xml Parser  Hi... please tell me about What parser would you use for searching a huge XML file? Thanks
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 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
DOM - XML
DOM  Hello.... I'm creating an xml file from java using DOM... from the database values... and saving it in a file But the created xml file..."),rs.getString("email")); } System.out.println("Xml File Created
Reading XML from a File
Reading XML from a File      ... a DOM document. JAXP (Java API for XML Processing) is an interface which provides... to create new DOM parsers. Some of the methods used for reading XML from a 
DOM - XML
DOM  Hi... I created an xml file through java by using DOM... downloadaction...for this But it didn't worked.. Its jus viewing the xml file... in advance  Hi Friend, Do you want the code in jsp or in java? Please
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 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, Sanjay   Hi Friend, Please
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
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
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
 

 

 

DMCA.com