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



Home Answers Viewqa JSP-Interview-Questions parsing xml file in jsp
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Java Coder
parsing xml file in jsp
2 Answer(s)      3 years and a month ago
Posted in : JSP-Interview Questions


example that pars XML file in JSP


Advertisement
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>


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
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
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... this xml file and write that xml part into file? can somebody
xml parsing - XML
how can i do this?   Hi friend, Parsing The XML File using DOM parser in JSP visit to : http://www.roseindia.net/jsp/parsing-xml.shtml...xml parsing  Hi i want to parse the xml document which contains US en
XML Parsing Error: mismatched tag. Expected: </br>. - JSP-Servlet
XML Parsing Error: mismatched tag. Expected: .  i had an error:"XML Parsing Error: mismatched tag. Expected: ." when uploading and writing them into an xml file. i use the jspBean to call the writeXML class. pls help me to solve
Xml parsing
Xml parsing  Hi..i tried the above code but I unable to know where can i place the xml file
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
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 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
parsing xml with jquery
parsing xml with jquery  Please explain how to parse a xml file into jquery. Thanks
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
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
parsing xml using sax
parsing xml using sax  how to get values if the root elements are same and their attributes are different
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
Handling Errors While Parsing an XML File
Handling Errors While Parsing an XML File   ... parsing an XML document. JAXP (Java API for XML Processing) is an interface which provides parsing of xml documents. Here the Document BuilderFactory is used
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
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... urgent. this is my xml file.... QWZ5671
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
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
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
Problem facing in SAX Parsing - XML
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... 0668420957700159USD you can find the above xml
write xml file with jsp useBean - JSP-Servlet
write xml file with jsp useBean  how to write into xml files with jsp... an org.w3c.dom.Document from XML. Save the xml file at bin file of C:\apache-tomat-5.5.23\bin... allows our application to obtain a Java XML parser. DocumentBuilderFactory
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
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... java.io import File from java.io import StringReader from org.xml.sax
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
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
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 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
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
 

 

 

DMCA.com