Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa XML how to parse xml document which contains elements with namespace using JDOM
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Shree
how to parse xml document which contains elements with namespace using JDOM
1 Answer(s)      6 years ago
Posted in : XML



Advertisement
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
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
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
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
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 namespace
XML namespace  hi.... please tell me about that What is an XML namespace prefix? thanks
XML namespace
XML namespace  Hi...... please tell me about that What characters are allowed in an XML namespace prefix? Thanks
XML namespace
XML namespace  hi... What is an XML namespace name? please tell me about that Thanks
XML namespace
XML namespace  Hi.... please anyone tell me Are the names of all element types and attributes in some XML namespace? thanks
XML namespace
XML namespace  Hi.... please anyone tell me Does the scope of an XML namespace declaration ever include the DTD? Thanks
XML namespace
XML namespace  hi... please anyone tell me about Can I use the same prefix for more than one XML namespace? Thanks
XML namespace
XML namespace  Hi.... please anyone tell me Can I resolve the URI used as an XML namespace name? thanks
XML namespace
XML namespace  Hi.... please anyone tell me about Can I use a relative URI as a namespace name? 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, JDOM Tutorial and example code.
An Overview of the XML-APIs Reading an XML document using JDOM Parsing The XML File Using JDOM Parser in JSP... will learn XML processing with JDOM API. The java examples discussed here explains
XML namespace
XML namespace  Hi.... please anyone tell me about What software is needed to process XML namespaces? Thanks
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
XML namespace
XML namespace  hi... please tell me about that What happens if there is no prefix on an element type name? thanks
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" >
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
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
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
Retrieving Data From the XML file
is only geared towards showing how to construct a Java object from an XML document... to actually parse the XML file to create our own Document object. Document object...;     In this example we will examine how to parse
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
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.... Program parses the xml file using the parse() method and creates a Document object
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="... some operation on the parsed xml document provided by jstl. scope
Advertisements
 

 

 

DMCA.com