In java we write JDBC code to connect MySQL in our application.Is there any process we write some code in MySQL script which help to run java application.
xml_retrieve.java
this file read xml and gives the node name and node value.....
NodeData.java
xml_output.jsp
I am sending string xml to retrieve the nodes and its value....its working gud..thn i am puting it arraylist.and whn it retrive the array list in jsp it doest show any result.
please help me out its very urgent..
or provide some other solution to show data in table in jsp.
submitting the same prob....please help me out..
private String getIndentSpaces(int indent)
{
StringBuffer buffer = new StringBuffer();
for (int i = 0; i < indent; i++) {
buffer.append(" ");
}
return buffer.toString();
}
/** Writes node and all child nodes into System.out
* @param node XML node from from XML tree wrom which will output statement start
* @param indent number of spaces used to indent output
*/
public NodeData writeDocumentToOutput(Node node,int indent)
// public void writeDocumentToOutput(Node node,int indent)
{
// get element name
//String nodeName = node.getNodeName();
//NodeList nodeName1;
NodeData nodeData=new NodeData();
String nodeName=node.getNodeName();
// get element value
String nodeValue = getElementValue(node);
// get attributes of element
NamedNodeMap attributes = node.getAttributes();
// for(int j=0;nodeName.getLength(); j++)
System.out.println(getIndentSpaces(indent) + "NodeName: " + nodeName + ", NodeValue: " + nodeValue);
// nodeData.setNodeName(nodeName);
for (int i = 0; i < attributes.getLength(); i++) {
Node attribute = attributes.item(i);
String attName=attribute.getNodeName();
String attValue=attribute.getNodeValue();
System.out.println(getIndentSpaces(indent + 2) + "AttributeName: " + attribute.getNodeName() + ", attributeValue: " + attribute.getNodeValue());
nodeData.setAttName(attName);
nodeData.setAttValue(attValue);
}
// write all child nodes recursively
NodeList children = node.getChildNodes();
for (int i = 0; i < children.getLength(); i++) {
Node child = children.item(i);
if (child.getNodeType() == Node.ELEMENT_NODE) {
writeDocumentToOutput(child,indent + 2);
}
}
return nodeData;
}
/** Saves XML Document into XML file.
* @param fileName XML file name
* @param doc XML document to save
* @return <B>true</B> if method success <B>false</B> otherwise
*/
public boolean saveXMLDocument(String fileName, Document doc) {
System.out.println("Saving XML file... " + fileName);
// open output stream where XML Document will be saved
File xmlOutputFile = new File(fileName);
FileOutputStream fos;
Transformer transformer;
try {
fos = new FileOutputStream(xmlOutputFile);
}
catch (FileNotFoundException e) {
System.out.println("Error occured: " + e.getMessage());
return false;
}
// Use a Transformer for output
TransformerFactory transformerFactory = TransformerFactory.newInstance();
try {
transformer = transformerFactory.newTransformer();
}
catch (TransformerConfigurationException e) {
System.out.println("Transformer configuration error: " + e.getMessage());
return false;
}
DOMSource source = new DOMSource(doc);
StreamResult result = new StreamResult(fos);
// transform source into result will do save
try {
transformer.transform(source, result);
}
catch (TransformerException e) {
System.out.println("Error transform: " + e.getMessage());
}
System.out.println("XML file saved.");
return true;
}
/** Parses XML file and returns XML document.
* @param fileName XML file to parse
* @return XML document or <B>null</B> if error occured
*/
public Document xml_retrieve(String xmlString) {
System.out.println("Parsing XML file... " + xmlString);
DocumentBuilder docBuilder;
Document doc = null;
DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
docBuilderFactory.setIgnoringElementContentWhitespace(true);
try {
docBuilder = docBuilderFactory.newDocumentBuilder();
}
catch (ParserConfigurationException e) {
System.out.println("Wrong parser configuration: " + e.getMessage());
return null;
}
InputSource is = new InputSource();
is.setCharacterStream(new StringReader(xmlString));
<%--
Document : index
Created on : Dec 31, 2010, 12:46:56 PM
Author : CDAC
--%>
<%@page import="java.util.*"%>
<%@page import="java.io.*,javax.xml.parsers.*,javax.xml.transform.*,org.servlet.*,javax.xml.transform.dom.*,javax.xml.transform.stream.*, org.w3c.dom.*;" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
String xmlString =
"<AvailablePackages>"
+ "<package packageName='NEW DELHI-MATARANI PACKAGE' packageCode='NDR00001' duration='3 Nights/4 Days' description='One of the holiest Hindu temples, the shrine of Vaishno Devi is dedicated to the Goddess Shakti. Affectionately also called as Mata Rani and Vaishnavi, the temple is the manifestation of the Mother Goddess. The temple is situated at an titleitude of 5200 ft., a distance of approx. 12 kms from Katra.' packageKeyname='vaishno-devi-package-tour' packageType='VAT'/>"
+ "<package packageName='NEW DELHI-SHIRDI PACKAGE' packageCode='NDR0023' duration='3 Nights / 4 Days' description='IRCTC proudly announces to relaunch SHIRDI PACKAGE with Charter Operations .Lord Sai Baba one of the most famous saints of India endowed with unprece dented powers and worshipped as a God incarnate. The life of Sai Baba is as wide and as deep as the infinite ocean; all can dive deep into it and take out precious gems in terms of knowledge and bhakti and distribute them.' packageKeyname='shirdi-package-tour' packageType='VAT'/>"
+" <package packageName='VAISHNO DEVI PACKAGE' packageCode='NDH028' duration='01 Night/02 Days' description='IRCTC presents Holiday package for JAMMU-KATRA-JAMMU, Mata Vaishno Devi Ji resides in a Holy Cave located in the folds of the three peaked mountain named Trikuta pronounced as Trikoot. The Holy Cave attracts lakhs of devotees every year' packageKeyname='vaishno-devi-package' packageType='VAT'/>"
+ "<package packageName='HIMALAYAN GLORY STANDARD PACKAGE' packageCode='WMH39S' duration='Nights/7 Days' description='Himalayan National Park, Poney and Yak Ride and One can see the endless Himalayan Panorama from Kufri, after lunch sight seeing of' packageKeyname='Amritsar_Dalhousie_tour' packageType='VAT'/>"
+ "<package packageName='DELHI-SHIMLA PACKAGE' packageCode='WMH32' duration='7 Night/ 8 Days' description='The former summer capital of the British in India, and the present capital of Himachal Pradesh, Shimla has been blessed with all the natural bounties w hich one can think of. It has got a scenic location; it is surrounded by green hills with snow capped peaks. Chandigarh, also called The Beautiful City, serves as the capital of two states, Punjab and Haryana, and is a union territory of India. The name translates from Hindi to English as the fort of Chandi, Chandi being a Hindu Goddess. Shimla bulging at its seams with unprecedented expansion, Sh imla retains its colonial heritage, with grand old buildings. Chandigarh known internationally for its architecture and urban planning, Chandigarh is home to numerous architectural projects of Le Corbusier, Pierre Jeanneret, Matthew Nowicki, and Albert Mayer , Serenity.' packageKeyname='shimla-delhi-holidays-packages' packageType='VAT' />"
+ "</AvailablePackages>";
String targetFileName = "c:/example2.xml";
xml_retrieve xml1=new xml_retrieve();
Document doc = xml1.xml_retrieve(xmlString);
// get root node of xml tree structure
Node root = doc.getDocumentElement();
ArrayList NodeName1=new ArrayList();
// write node and its child nodes into System.out
System.out.println("Statemend of XML document...");
xml1.writeDocumentToOutput(root,0);
System.out.println("... end of statement");
// write Document into XML file
// xml1.saveXMLDocument(targetFileName, doc);
//String NodeValue1=(String)session.getAttribute("NodeValue1");%>
<table>
<tr>
<td>
<%
System.out.println("Result"+NodeName1);
for (Iterator iter = NodeName1.iterator(); iter.hasNext(); )
{
String res=(String)iter.next();
System.out.println("RES:"+ res);
%>
<%= res %>
</td>
</tr>
<%}%>
</table>
</body>
</html>
I am sending string xml to retrieve the nodes and its value....its working gud..thn i am puting it arraylist.and whn it retrive the array list in jsp it doest show any result.
please help me out its very urgent..
or provide some other solution to show data in table in jsp.
[Fatal Error] :1:982: Element type "package" must be followed by either attribute specifications, ">" or "/>".
Wrong XML file structure: Element type "package" must be followed by either attribute specifications, ">" or "/>".
i m using the following xml...
"<AvailablePackages>"
+ "<package packageName='NEW DELHI-MATARANI PACKAGE' packageCode='NDR00001' duration='3 Nights/4 Days' description='One of the holiest Hindu temples, the shrine of Vaishno Devi is dedicated to the Goddess Shakti. Affectionately also called as Mata Rani and Vaishnavi, the temple is the manifestation of the Mother Goddess. The temple is situated at an titleitude of 5200 ft., a distance of approx. 12 kms from Katra.' packageKeyname='vaishno-devi-package-tour' packageType='VAT'/>"
+ "<package packageName='NEW DELHI-SHIRDI PACKAGE' packageCode='NDR0023' duration='3 Nights / 4 Days' description='IRCTC proudly announces to relaunch SHIRDI PACKAGE with Charter Operations .Lord Sai Baba one of the most famous saints of India endowed with unprece dented powers and worshipped as a God incarnate. The life of Sai Baba is as wide and as deep as the infinite ocean; all can dive deep into it and take out precious gems in terms of knowledge and bhakti and distribute them.'packageKeyname='shirdi-package-tour' packageType='VAT'/>"
+ "</AvailablePackages>"
whn i m using the single tag of package it is working fine.....