|
|
| xml or database |
Expert:PontLay
If I implement some web applications, which is a better way to retrieve and parse xml file directly using DOM or storing those xml files in Database and retrieve. My xml files will be about 100 - 200 and each file will have 30-50 records. |
| Answers |
Hi friend,
Code to help in solving the problem :
"parsingxml.jsp"
<%@ page import= "org.jdom.*, java.util.*, org.jdom.input.SAXBuilder" %> <% SAXBuilder saxBuilder = new SAXBuilder(); Document doc = saxBuilder.build ("http://localhost:8080/ServletExample/roseindia.xml"); %> <html> <head><title>Parsing of xml using JDOM</title></head> <body> <h1><font color='green'>Employees of Roseindia</font></h1> <table border="2"> <tr> <th><font color='blue'>Name of Employee</font></th> <th><font color='blue'>Date of Birth</font></th> <th><font color='blue'>City</font></th> </tr> <% List list = doc.getRootElement().getChildren(); Iterator iter = list.iterator(); while (iter.hasNext()){ Element element = (Element) iter.next(); List NameDOBCity = element.getChildren(); Iterator listIter = NameDOBCity.iterator(); %> <tr> <% while ( listIter.hasNext() ){ Element childNode = (Element) listIter.next(); %> <td><%= childNode.getText() %></td> <% } } %> </tr> </table> </body> </html>
"roseindia.xml"
<?xml version="1.0" encoding="ISO-8859-1"?>
<roseindia>
<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>
<employee> <name>Vineet Bansal</name> <date-of-birth>05-02-83</date-of-birth> <city>Sonipat</city> </employee>
<employee> <name>Vikas Singh</name> <date-of-birth>05-12-88</date-of-birth> <city>Hazipur</city> </employee>
<employee> <name>Anusmita Singh</name> <date-of-birth>28-12-84</date-of-birth> <city>Bareilly</city> </employee>
</roseindia>
Thanks
|
| More Questions |
|
|
Post Answers
Ask Question
Facing Programming Problem?
|
|
|
|
|