how to parse xml document which contains elements with namespace using JDOM

how to parse xml document which contains elements with namespace using JDOM

View Answers

November 19, 2008 at 1:04 AM

Hi friend,


Code to help in solving the problem :

"roseindia.xml"

<?xml version="1.0" encoding="ISO-8859-1"?>

<roseindia>

<employee>
<name>Vineet Bansal</name>
<date-of-birth>05-02-83</date-of-birth>
<city>Sonipat</city>
</employee>

<employee>
<name>Sandeep Kumar Suman</name>
<date-of-birth>15-02-84</date-of-birth>
<city>Gorakhpur</city>
</employee>

<employee>
<name>Amit Raghuvanshi</name>
<date-of-birth>19-12-86</date-of-birth>
<city>Lucknow</city>
</employee>

</roseindia>

"parsingxml.jsp"

<%@page import="org.w3c.dom.*, javax.xml.parsers.*" %>
<%
DocumentBuilderFactory docFactory =
DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
Document doc = docBuilder.parse
("http://localhost:8080/ServletExample/roseindia.xml";);
%>
<%!
public boolean isTextNode(Node n){
return n.getNodeName().equals("#text");
}
%>
<html>
<head><title>Parsing of xml using DOM Parser</title></head>
<body>
<h2><font color='green'>Employees of Roseindia</font></h2>
<table border="2">
<tr>
<th>Name of Employee</th>
<th>Date of Birth</th>
<th>City</th>
</tr>
<%
Element element = doc.getDocumentElement();
NodeList personNodes = element.getChildNodes();
for (int i=0; i<personNodes.getLength(); i++){
Node emp = personNodes.item(i);
if (isTextNode(emp))
continue;
NodeList NameDOBCity = emp.getChildNodes();
%>
<tr>
<%
for (int j=0; j<NameDOBCity.getLength(); j++ ){
Node node = NameDOBCity.item(j);
if ( isTextNode(node))
continue;
%>
<td><%= node.getFirstChild().getNodeValue() %></td>
<%
}
%>
</tr>
<%
}
%>
</table>
</body>
</html>

For more information on XML visit to :

http://www.roseindia.net/xml/

http://www.roseindia.net/jsp/parsing-xml.shtml

Thanks









Related Tutorials/Questions & Answers:
how to parse xml document which contains elements with namespace using JDOM - XML
how to parse xml document which contains elements with namespace using JDOM  Hello, I am parsing XML file ,which has structure like... is inside so how can i parse this xml using JDOM,java. Thanks Shree  Hi
Reading an XML document using JDOM
Reading an XML document using JDOM       This Example shows you how to Read an XML document by using JDOM.eplace a node with existing node in a DOM document. JDOM is used
Advertisements
Parsing The XML File Using JDOM Parser in JSP
with JDOM parser to parse the xml document. JDOM can read existing XML documents... native parser. XML parsing produces an xml parse tree from an XML document. Using... Parsing The XML File Using JDOM Parser in JSP
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... and getter , i dont know how to differentiate that this for example: line in xml
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 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
XML namespace
XML namespace  hi... What is an XML namespace name? please tell me about thatADS_TO_REPLACE_1 Thanks
XML namespace
XML namespace  hi.... please tell me about that What is an XML namespace prefix?ADS_TO_REPLACE_1 thanks
XML namespace
XML namespace  Hi.... please anyone tell me Does the scope of an XML namespace declaration ever include the DTD?ADS_TO_REPLACE_1 Thanks
XML namespace
XML namespace  Hi...... please tell me about that What characters are allowed in an XML namespace prefix?ADS_TO_REPLACE_1 Thanks
XML namespace
XML namespace  Hi.... please anyone tell me Can I resolve the URI used as an XML namespace name?ADS_TO_REPLACE_1 thanks
XML namespace
XML namespace  Hi.... please anyone tell me Are the names of all element types and attributes in some XML namespace?ADS_TO_REPLACE_1 thanks
Parsing XML using Document Builder factory - XML
Parsing XML using Document Builder factory  Hi , I am new to XML . I am trying to parse a XML file while is : For this i am using Document... for all tags except for the tag . I am not sure how to read the attribute
JDOM CDATA Example, How to add CDATA section in xml document.
JDOM CDATA Example, How to add CDATA section in xml document. In this tutorial, we will see how to add CDATA section in xml document. In xml document...;xml ="Company.xml";   File  file=new File(xml
XML namespace
XML namespace  Hi.... please anyone tell me about Can I use a relative URI as a namespace name?ADS_TO_REPLACE_1 Thanks
XML namespace
XML namespace  hi... please anyone tell me about Can I use the same prefix for more than one XML namespace?ADS_TO_REPLACE_1 Thanks
Parsing repeatitive xml elements using SAX Parser - XML
Parsing repeatitive xml elements using SAX Parser  Hi, I'm using SAX Parser to read an XML file. My XML file contains repeatitive tags. I'm.... Could anyone let me know how to retrieve values from repeatitive tags using
how to parse xml in j2me tutorial
how to parse xml in j2me tutorial   i want to parse xml file in j2me wireless toolkit.i saw ur examples & source code for parsing xml file in j2me & i try to execute same example on my pc i some how manage to run
Getting all XML Elements
elements of the XML file using the DOM APIs. This APIs provides some constructors and methods which helps us to parse the XML file and retrieve all elements... elements. Program parses the xml file using the parse() method and creates
How Compare 2 xml files with JDOM - Java Beginners
How Compare 2 xml files with JDOM  Hi I'm want help on how can I compare 2 xml files using JDOM in java and identify whether have the same content or not My files can simply be File1 File2
XML namespace
XML namespace  Hi.... please anyone tell me about What software is needed to process XML namespaces?ADS_TO_REPLACE_1 Thanks
XML namespace
XML namespace  hi... please tell me about that What happens if there is no prefix on an element type name?ADS_TO_REPLACE_1 thanks
DOM Parser Example to Parse A DOM Document
DOM Parser Example to Parse A DOM Document In this tutorial, we will discuss about how to parse(retrieve data) DOM Document. The XML DOM views an XML document as a tree-structure. In this program, we read the XML file and print
xml document parsing
xml document parsing   Hi Guys, Xml document has been inserted into the database,how do i parse the xml document stored in database,so that xml document can be retrieved on to JSP file using jdbc/odbc connection. Please help me
Retrieving Data From the XML file
is only geared towards showing how to construct a Java object from an XML document... to parse method to actually parse the XML file to create our own Document object... of the elements in our XML document name message. NodeList object will be obtained
How to parse an XML as per dtd in java
How to parse an XML as per dtd in java  Please help to tell me a logic to parse an xml as per mentioned dtd inside xml. I've used SAX and DOM both but that only check for well formed xml tags but don't validate as per DTD. please
parse xml
; </STATE> How to parse the above xml. please help me   Here is a code that parses an xml file using DOM Parser. import org.w3c.dom.*; import...parse xml   <STATES> <STATE sname="AndhraPradesh" >
JDOM, JDOM Tutorial and example code.
document using JDOM Parsing The XML File Using JDOM Parser in JSPADS_TO_REPLACE_3... will learn XML processing with JDOM API. The java examples discussed here explains... Java API for manipulating XML files within Java Program. The JDOM API supports
how to develope an xml document with existing documents's body content?
how to develope an xml document with existing documents's body content?  Hi, i'm working with content optimization system.I want to know how we can... with that content.I'm using JDOm in my project.Could anybody help me to know about this as i'm
Get XML Elements
of all elements contained in the XML document . Description of the program:ADS_TO_REPLACE_1 The following program teaches to parse the elements and retrieve ... Get XML Elements      
how to parse a csv file using standard libraries?
how to parse a csv file using standard libraries?  hie i am a beginner in java i want to parse a csv file using any standard libraries i want to know how the libraries are imported and used in eclipse thanks in advance
read xml elements
read xml elements  i want read xml data using sax parser in java. but is there any classes or methods to read xml elements
read xml elements
read xml elements  i want read xml data using sax parser in java. but is there any classes or methods to read xml elements
Simple Types elements
There are two types of elements: 1. Simple Type 2. Complex TypeADS_TO_REPLACE_1 Simple types are those which contains only text and not any child elements. XML Schema specification provides a lot of built-in simple data types and you
the array list contains similar type of elements or disimilar type of elements
the array list contains similar type of elements or disimilar type of elements  the array list contains similar type of elements or disimilar type of elements
Create - XML File (Document)
Create - XML File (Document)       In this section, you will  learn to create a XML document using the DOM APIs. This XML document uses  1.0 version  and UTF-8
Use of <x:parse> tag of JSTL
:parse> tag of  Xml tag library of Jstl. This tag is used to parse the specified xml document. Standard Syntax : <%@ taglib prefix="x" uri="... to perform some operation on the parsed xml document provided by jstl
How to merge two word document using java
How to merge two word document using java   how to merge two word document using java
How to merge two word document using java
How to merge two word document using java   how to merge two word document using java
To Count XML Element
) at the console and checks its availability. It parses the xml document using the parse() method. After parsing the XML document it asks for element name which... Document Contains 3 elements. Download source code of the project
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
XML Elements
Relationships Elements in a xml document are related as parents and children... XML Elements       XML Elements are extensible. They have relationships. They have simple naming
XML Count Elements
; that are used in your XML document using the SAX parser.  Description of program:ADS_TO_REPLACE_1 Developing a java program, you need a XML well-formed document... XML Count Elements      
how to edit xml file which is currently running in web server - XML
how to edit xml file which is currently running in web server  Hello, I want to add new element in xml file which is currently running in my web server apache tomcat.I can add and modify xml file by giving Path like that "E
creating document in XML - XML
creating document in XML  Create an XML document for catalogue...)); System.out.print("Enter number to add elements in your XML file: "); String... = documentBuilderFactory.newDocumentBuilder(); Document
how to display duplicate elements with out using collection Frame work?
how to display duplicate elements with out using collection Frame work?  how to display duplicate elements with out using collection Frame work
XML Validate DTD
file. After creating these, we parse the xml file using the parse() method... a  DTD (Document Type Definition)  using the DOM APIs. A DTD defines  the document structure with a list of legal elements and attributes
XML Interviews Question page19
name, which the application parses to determine what XML namespace the local name...;1.0">     How do I use the default XML namespace... document to another document. An early draft of the XML namespaces recommendation
Processing XML with Java
elements and attributes for the document. This can be defined inside the xml... for Document Object Model. It is read write api so can parse xml document... the xml document. JDOM can create a new in memory XML tree like DOM and it can
Java XML Parsing Using DOM
Java XML Parsing Using SAX To Parse XML document using SAX parser method you... = saxParserFactory.newSAXParser(); // Parsing XML Document by calling parse... saxParser = saxParserFactory.newSAXParser(); // Parsing XML Document

Ads