parsing xml file in jsp

Ads
 

parsing xml file in jsp

example that pars XML file in JSP

View Answers

August 24, 2011 at 12:08 PM

<%@page import="org.w3c.dom.*, javax.xml.parsers.*" %>
<%
  DocumentBuilderFactory docFactory = 
  DocumentBuilderFactory.newInstance();
  DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
  Document doc = docBuilder.parse("C:/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>Address</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 nl = emp.getChildNodes(); 
  %>
  <tr>
  <%
  for (int j=0; j<nl.getLength(); j++ ){
  Node node = nl.item(j);
  if ( isTextNode(node)) 
  continue;
  %>
  <td><%= node.getFirstChild().getNodeValue() %></td>
  <%
  } 
  %>
  </tr>
  <%
  }
  %>
  </table>
  </body>
</html>

August 24, 2011 at 12:09 PM

Here is the roseindia.xml:

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

  <employee>
    <name>A</name>
    <address>Delhi</address>
  </employee>

  <employee>
    <name>B</name>
    <address>Delhi</address>
  </employee>

  <employee>
    <name>C</name>
    <address>Delhi</address>
  </employee>

  <employee>
    <name>D</name>
   <address>Delhi</address>
  </employee>

  </roseindia>

Ads









Related Tutorials/Questions & Answers:
parsing xml file in jsp
parsing xml file in jsp  example that pars XML file in JSP
parsing xml file using java code
parsing xml file using java code  parsing a xml file using java code
Advertisements
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
XML parsing to Mysql database
XML parsing to Mysql database  Can someone please post the code for parsing an XML file into Mysql database using SAX
parsing xml with jquery
parsing xml with jquery  Please explain how to parse a xml file into jquery. Thanks
Xml parsing
Xml parsing  Hi..i tried the above code but I unable to know where can i place the xml file
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
xml parsing
xml parsing  my task is when i wll give java file to a program that program interpret that file separate each and every keywords and indentifiers and return the csv file that contains count of used keywords and idenfiers by using
XML to JSP
an xml file and display the data into jsp file...XML to JSP  How to access the following XML tag Title tag in JSP   Please visit the following link: http://www.roseindia.net/jsp
parsing xml using sax
parsing xml using sax  how to get values if the root elements are same and their attributes are different
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
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... XML file also(wrong format),shows result in JSP page but server shows
HOW TO STORE MULTIPLE EMPLOYEE DETAILS TO XML FILE USING JSP?
HOW TO STORE MULTIPLE EMPLOYEE DETAILS TO XML FILE USING JSP?  HELLO... EMPLOYEES SHOULD BE SAVED IN XML FILE AND MY SQL DATABSE TABLES AT A TIME, AND ALSO HELP ME OUT WITH HOW TO VIEW THE STORED DATA IN XML FILE USING EMPNAME. PLEASE
Ignoring Comments While Parsing an XML File
Ignoring Comments While Parsing an XML File   ... in an XML File. JAXP is an interface which provides parsing of xml documents. Here... it from the File. Xml code for the program generated
Truncating issue while parsing XML with SAX Parser.
Truncating issue while parsing XML with SAX Parser.  I am Parsing one xml file and after parsing I have to enter the data into the database using hibernate. The problem is while parsing some elements, its not getting the complete
Problem facing in SAX Parsing - XML
of all remove & sign from your xml file,it contradicts.And then try...Problem facing in SAX Parsing  I have facing the issue in SAX Parsing like i have got the xml and the xml structure is like below
How to access the Title tag from xml to jsp
tag from xml to jsp   Please visit the following link: http://www.roseindia.net/jsp/parsing-xml.shtml The above link will provide you an example that will read an xml file and display the data into jsp file
problems in parsing the xml with the special characters
problems in parsing the xml with the special characters  Hi, I have a problem, in while parsing the xml with special characters apstrophe('). I am... parse this string in xml path. i am not able to fetch the adam's string in the xml
Data needs to be gathered in XML file from the database (MySql) using JSP
in XML file from the database (MySql) using appropriate JSP/Java Bean functions...Data needs to be gathered in XML file from the database (MySql) using JSP  on index.jsp page, where the user will be able to search, with search
XML Parsing from php web server in J2ME
XML Parsing from php web server in J2ME  Hello Team, You gave some tips for XML parsing in java, i need some additional tips for xml parsing from php web server in j2me... Thanks and Regards Alagu
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
How to store data entered by User in JSP page in XML file
  JSP store data entered by user into XML file 1)form.jsp: <html>...How to store data entered by User in JSP page in XML file  How to store data entered by user in JSP page to be saved in XML file.On clicking submit
how to append data to XML file in proper format using JSP
how to append data to XML file in proper format using JSP  hello i was appending my XML file to add more data entered by user in JSP page.But not getting XML file in proper format as XML rules.lease help me to get XML file
complex xml parsing and storing in database - XML
complex xml parsing and storing in database  Hi Experts ,i want to parse my xml document and store it in mysql database. This is my code. How to parse this complex data. EDI_DC40 800 0000000000557748
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... to do xml parsing help me for that... Regards Alagu
How to store data entered in JSP page by a user in XML file & later retrieval of data using id at other page
How to store data entered in JSP page by a user in XML file & later retrieval... by user to be stored in xml file.here you have entered data in JSP file... file.How can i store data entered by user in XML file and later retrieve data
Parsing The XML File using DOM parser in JSP
Parsing The XML File using DOM parser in JSP... provides actions for parsing an XML document. This example helps you to parsing the xml page in jsp. 'parsingxml.jsp' uses 'roseindia.xml' file and display its
Exception during parsing a parameter from the form in JSP
Exception during parsing a parameter from the form in JSP  Exception during parsing params from a form? I get parameters from a html form. I parse the integer one in the JSP file, but I get exception. Is there anyway I can get
Question about parsing XML document with DOM in JAVA.
Question about parsing XML document with DOM in JAVA.  Hi, I need to parse a XML file witch has info about classes. So i have for each class to have... it with multiple for loops, one iside the other but it doesnt work. My XML is this below
How to access the following tag from xml to jsp
the title where cat="1" and "My Title" from XML File?   Please visit the following link: http://www.roseindia.net/jsp/parsing-xml.shtml The above link will provide you an example that will read an xml file and display the data
XML Transformation in JSP
to demonstrate XML Transformation tag in JSP This example illustrate use of XML transformation tag in JSP file. This example performs transformation from an XML... XML Transformation in JSP  

Ads