XML with JAVA

XML with JAVA

View Answers

May 31, 2009 at 10:24 AM

//DOM PARSER
import java.io.*;
import org.w3c.dom.*;
import javax.xml.parsers.*;

class XmlDemo
{
public static void main(String[] args)
{
//System.out.println("Hello World!");
try
{
DocumentBuilderFactory dbf;
DocumentBuilder db;

dbf = DocumentBuilderFactory.newInstance();
db = dbf.newDocumentBuilder();

File f = new File("catalog.xml");
Document xmldoc = db.parse(f);

NodeList nl = xmldoc.getElementsByTagName("college");

//System.out.println(nl.getLength());

Node root = nl.item(0);

NodeList nl1 = root.getChildNodes();

//System.out.println("No. of .Nodes : " + nl1.getLength());

for (int i = 0; i< nl1.getLength(); i++)
{
Node n = nl1.item(i);

if(n.getNodeType() == 1)
{
System.out.println("Node Name : " + n.getNodeName());
NamedNodeMap nnm = n.getAttributes();
Node nid=nnm.getNamedItem("id");

System.out.println("Attribute Value : " + nid.getNodeValue());

NodeList innerNodes = n.getChildNodes();

//System.out.println("Inner Nodes : " + innerNodes.getLength());

for(int j=0; j<innerNodes.getLength(); j++)
{
Node n1 = innerNodes.item(j);

if(n1.getNodeType() == 1)
{
System.out.println("Node Name : " + n1.getNodeName());
System.out.println("Node Value : " + n1.getFirstChild().getNodeValue());

}
}
System.out.println("******************************************************");
}

}
}
catch (Exception e)
{
e.printStackTrace();
}
}
}









Related Tutorials/Questions & Answers:
Java + XML - XML
Java + XML  1) I have some XML files, read one xml... java...the attribute value..not sure now how to read the xml file passing..." pointing to a hello xml file ..read that file and get the value of the parent
java and xml - XML
java and xml  Hi Deepak, I want learn xml and java(applications). Which editor is best usefull(trial--version) in my applications...; Hi friend, http://www.roseindia.net/xml/dom/ Thanks
Advertisements
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
java and xml - XML
java and xml   test_final_1 2009-025T13:23:45 B2B I want to validate each tag.. and i don't have any xsd.. kindly help me to solve...://www.roseindia.net/xml/dom/DOMValidateDTD.shtml Thanks
XML with JAVA - XML
document and the processing in JAVA program . Find the time for each XML element...XML with JAVA  Hi.. This is Priya here. Thanks for responding me. I have a query. "Write program in java to evaluate the time to access
java and xml problem - XML
java and xml problem  hi, i need to write a java program that generates an xml file as follows: aaa vvv --------- i have witten a program in java, but im
java with xml
java with xml  Hi i am reading xml data with sax parser in java. ok its fine. But in future xsd and xml will change. now my question is if xsd and XML will change my java progrm will not change. is it possible ? Thanks
java with xml
java with xml  Hi i am reading xml data with sax parser in java. ok its fine. But in future xsd and xml will change. now my question is if xsd and XML will change my java progrm will not change. is it possible ? Thanks
XML in java - XML
XML in java  Write a program using SAX that will count the number of occurrences of each element type in an XML document and display them...://www.roseindia.net/xml/sax/SAXElementCount.shtml Hope that it will be helpful
Read XML in java - XML
Read XML in java  Hi Deepak, I want to read a xml file which have only one element with multiple attributes with same tag name. here is my file... a solution.my java code is given below. import java.io.File; import
java - XML
This is my XML file then how can read this XML file Using DOM & SAX parsers in java? How can write the same data into XML file using DOM parser? Could you
java with xml
java with xml  hi i have a problem. // this sample code is reading xml file in java DefaultHandler handler = new DefaultHandler... xml file change in future then my java code will also change. but is there any
java - XML
java  How can write data into XML file using DOM parser? How can convert HTWL file to XML file
java - XML
java  how can i validate my xml file using java code plz send me de... kumar  Hi friend, Step to validate a xml file against a DTD (Document Type Definition) using the DOM APIs. Here is the xml file "User.xml
XML and java
XML and java  Hi I have xml data in XMLStreamreader object how to retrive tha data and write into a file using java Your help will be much appreciated Thanks   Hi Friend, Try the following code: import java.io.
java - XML
java  How to prepare an xml document by reading data from a table in the database . (the database access logic is written inside the servlet
java - XML
you get the data3. And in the servlet class you can use the DOM api to create xml... it to the xml treedoc.appendChild(root);For more information please visit http://www.roseindia.net/xml/dom/createdomchildelement.shtmlThanks
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
in the XML document while i am parsing the file using SAX event based parser.... provide the way in java.  Hi Friend, Try the following code: import... parser = parserFact.newSAXParser(); System.out.println("XML Data
xml to html via java
xml to html via java  how to read xml into html using java code
java - XML
java  How to read the values of XMLStreamConstants.CDATA in simple java
JAVA - XML
JAVA  hi.. i want to talk to any SWT expert in JAVA... how can i do it?   Hi friend, For read more information,Examples and Tutorials on SWT visit to : http://www.roseindia.net/tutorials/swt/ Thanks
Java XML
Java XML In this section we will learn how to manipulate XML files in Java program. Java provides excellent API for manipulating the XML files. In your Java... the XML files. API's for XML parsing in Java: DOM The DOM API
xml file creation in java
xml file creation in java  how to create xml file in java so...; Please visit the following links: http://www.roseindia.net/tutorial/java/xml...;Please visit the following links: http://www.roseindia.net/tutorial/java/xml
Validation on input xml in java program - XML
Validation on input xml in java program  Hi.. i am accepting xml data as input which I have to use in my program. i have to validate this input xml against some schema using xml beans and NOT by using sax or dom parser. I am
XMl and Java web services
XMl and Java web services  I want to do a project on java web services and XML. I wanted to ask, how the data entered by user through the HTML file can be converted to an XML file and sent to the server? At the server site, how
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_TO_REPLACE_1 http://www.roseindia.net/xml/Listingnode.shtml http://www.roseindia.net
turn the GUI(java class) into XML - XML
turn the GUI(java class) into XML   Hi im trying to turn the GUI(java class) into XML ,means in my gui one combobox is there if i select one... xml one tag is there,in that mapname="somename" active="true" options are there.In
Question on java & XML
Question on java & XML  How do we convert the names of files and subfolders into an xml file... Suggestions needed...what are classes we need to use
how to update xml from java - XML
how to update xml from java  hi, Im new to xml parsing and dont know much about. I need to modify the attribute val of a tag in a complex xml file by using java code tell me the procedure. Thanks in advance.   hi
java code - XML
java code  Write a program using SAX that will count the number of occurrences of each element type in an XML document and display them. The document file to be processed should be identified by the first command-line argument
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
Java-XML Xerces/Jaxp
Java-XML Xerces/Jaxp  Im new to Java DOM development. I have doubt or I am bit unclear about fact of JAXP and Xerces. My question is why developer use xerces when jaxp does the job
Java-XML Xerces/Jaxp
Java-XML Xerces/Jaxp  Im new to Java DOM development. I have doubt or I am bit unclear about fact of JAXP and Xerces. My question is why developer use xerces when jaxp does the job
how to create xml schema from xml doc using java
how to create xml schema from xml doc using java  i want to create xml schema from xml document programatically using java... am using Netbeans IDE 7.0 i hav created the xml document for a table of data from Database... now i
how to get this xml syntx in java??????
how to get this xml syntx in java??????  how to get this xml syntx in java?????? < comp xlink:type="new" xlink:actuate="onload"/>
how to get this xml syntx in java??????
how to get this xml syntx in java??????   how to get this xml syntx in java?????? < comp xlink:type="new" xlink:actuate="onload"/>
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
Read XML using Java
of all i need to read xml using java . i did good research in google and came to know...://www.roseindia.net/xml/sax/EmployeeDetails.shtml http://www.roseindia.net/java/example/java/xmlParsing/java-xml-parsing-using-sax.shtml http://www.roseindia.net/xml/sax
XML - XML
XML XSD validation in java  Can anyone help in writing validation for XML XSD in Java
xml creation in java
xml creation in java  HI, I need a java program to create an xml file... therez a tutorial in your site to create an xml file at http://www.roseindia.net/xml/dom/CreatXMLFile.shtmlADS_TO_REPLACE_1 but this isn't creating
XML-JAVA - Java Beginners
XML-JAVA  How to create XML file and write to this file in JAVA...,contactNo,email); System.out.println("Xml File Created Successfully...://www.roseindia.net/xml/dom/CreatXMLFile.shtml Thanks
Version of com.nfbsoftware>java-xml dependency
List of Version of com.nfbsoftware>java-xml dependency
XML in JAVA - Java Beginners
XML in JAVA  hi.. i have an XML file .. and i have parsed... in another file to get all the elements in the documents.. but my java SDK(i.e Eclipse) gives Java Null Pointer exception... can anyone tell me what could be wrong
Java Program - XML
Java Program  Write a Java code that will use a DTD to create a XML..., To create XML using DTD,you need to create a dtd 'students.dtd': Now create java file 'CreateXML.java' import java.io.*; import org.w3c.dom.
Java Xml Data Store
Java Xml Data Store  I have to do this project and i'm finding it so hard its way over my head if any one has any ideas or help. What would the best... or XML file. As a good Java programmer you will use correct Object-Oriented
Java and converting a PDF to XML
Java and converting a PDF to XML  I reviewed your example - https://www.roseindia.net/tutorial/java/xml/pdftoXML.html - and on many users group, it receives high praise. I understand it uses iText but I am having a problem
Java and converting a PDF to XML
Java and converting a PDF to XML  I reviewed your example - https://www.roseindia.net/tutorial/java/xml/pdftoXML.html - and on many users group, it receives high praise. I understand it uses iText but I am having a problem
creating Xml - Java Beginners
creating Xml  how we can create a xml file using java Creating XML File is possible in java with this packages. import... this Elemnts to DOcumnet object. Creating XML File is possible  Creating XML File is possible
java with xml parsing - Java Beginners
java with xml parsing  Hi, I need the sample code for parsing complex data xml file with java code. Example product,category,subcategory these type of xml files and parse using java. Please send the code immediately its very

Ads