• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

create a xml from getting values from html forms

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
using servlets how to create a xml from getting the values for the xml from html forms...
1)i hav created a html form ..how can i convert the values to a xml form...
[ August 05, 2008: Message edited by: aru man ]
 
Sheriff
Posts: 67645
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please be sure to take the time to compose descriptive subjects for your posts; read this for more information.

Using a title of "servlets" in a forum completely dedicated to questions on Servlets isn't very helpful.

You can go back and change your post to add a more meaningful subject by clicking the .
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The simplest way to create an XML document given values that you have obtained from an HTML request in the usual way is to just write plain text.

Where does the resulting XML have to go? Using standard java you can write to a file or a String in memory or a variety of other output streams.

Do you have a sample of what the XML is supposed to look like?

Bill
 
aru man
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
i have generated the xml from html form....
the code is as below..


import java.io.*;
import javax.servlet.Servlet;
import javax.servlet.ServletException;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import javax.xml.parsers.*;
import javax.xml.transform.*;
import javax.xml.transform.dom.*;
import javax.xml.transform.stream.*;
import org.w3c.dom.*;


/**
* @version 1.0
* @author
*/
public class servxml extends HttpServlet implements Servlet {

/**
* @see javax.servlet.http.HttpServlet#void (javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException
{
resp.setContentType("text/html");
//BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
PrintWriter out = resp.getWriter();
//ring root = req.getParameter("root");
String c="class1";
String c1="method";
String c2="param";


String s = req.getParameter("class1");
String s1 = req.getParameter("method");
String s2 = req.getParameter("param");
try{

DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document document =db.newDocument();
String root = req.getParameter("root");
Element rootElement = document.createElement(root);
document.appendChild(rootElement);

//Element em = document.createElement(class);
Element em = document.createElement(c);
em.appendChild(document.createTextNode(s));
rootElement.appendChild(em);


Element er = document.createElement(c1);
er.appendChild(document.createTextNode(s1));
rootElement.appendChild(er);

Element et= document.createElement(c2);
et.appendChild(document.createTextNode(s2));
rootElement.appendChild(et);


TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
DOMSource source = new DOMSource(document);
StreamResult result = new StreamResult(System.out);
transformer.transform(source, result);
out.println("<html><body>");
out.println("<h3>xml created");
out.println("</body></html>");

}
catch(Exception e){e.printStackTrace();
}


}
}


but i am getting the result in console...
1)
how to display it in next window..
 
aru man
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
William can you just post your way of coming to the solution so that it could be helpful to me......
 
aru man
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
William can you just post your way of coming to the solution so that it could be helpful to me......
 
Bartender
Posts: 2856
10
Firefox Browser Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi aru man welcome to Javaranch ,
And please UseCodeTags.
Unformatted code is difficult to read so most people might just ignore it.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic