[jdom-interest] parsing XML using JDOM.....Please help!

Naveen My perlnaveen at yahoo.com
Mon Jul 7 06:30:55 PDT 2003


Hello ,
I am using below code to get data from .html FORM and then buid XML.
Presently,I am writing the XML I generated to the browser.
 
I would like to parse the XML thatw as generated and get the values out to insert in the database using JDBC.I know how to use JDBC(connectin,statement,execution ....)
 
All I am looking for is to parse the XML doc I create and get the values out ...so that I can insert the values in the database....
 
Your help is highly appreciated....
thanks
naveen
 
 
import java.io.*;
import java.text.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import org.jdom.*;
import org.jdom.input.*;
import org.jdom.output.*;

public class XML3 extends HttpServlet
{
    public void doGet(HttpServletRequest request,
                      HttpServletResponse response)
        throws IOException, ServletException
    {
        response.setContentType("text/xml");
        PrintWriter out = response.getWriter();
        try
        {
            Element studentRegistration = new Element("studentRegistration");
            
            Element studentID = new Element("studentID");
            studentID.addContent(request.getParameter("studentID"));
            studentRegistration.addContent(studentID);
 
            Element firstName = new Element("firstName");
            firstName.addContent(request.getParameter("firstName"));
            studentRegistration.addContent(firstName);
 
            Element lastName = new Element("lastName");
            lastName.addContent(request.getParameter("lastName"));
            studentRegistration.addContent(lastName);
 
            Element ssn = new Element("ssn");
            ssn.addContent(request.getParameter("ssn"));
            studentRegistration.addContent(ssn);
 
            Element address = new Element("address");
            address.addContent(request.getParameter("address"));
            studentRegistration.addContent(address);
 
            Element city = new Element("city");
            city.addContent(request.getParameter("city"));
            studentRegistration.addContent(city);
 
            Element state = new Element("state");
            state.addContent(request.getParameter("state"));
            studentRegistration.addContent(state);
 
            Element zip = new Element("zip");
            zip.addContent(request.getParameter("zip"));
            studentRegistration.addContent(zip);
 
            Element emailAddress = new Element("emailAddress");
            emailAddress.addContent(request.getParameter("emailAddress"));
            studentRegistration.addContent(emailAddress);
 
            Element userID = new Element("userID");
            userID.addContent(request.getParameter("userID"));
            studentRegistration.addContent(userID);
 
            Element password = new Element("password");
            password.addContent(request.getParameter("password"));
            studentRegistration.addContent(password);

            Document studentRegistrationdoc = new Document(studentRegistration);
            
            XMLOutputter xout = new XMLOutputter(" ", true);
            xout.output(studentRegistrationdoc, out);
            System.out.println(xout);
       }
       catch (Exception e)
       {
            e.printStackTrace();
       }
    }
    public void doPost(HttpServletRequest request,
                      HttpServletResponse response)
        throws IOException, ServletException
    {
        doGet(request, response);
    }
}
 



---------------------------------
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://jdom.org/pipermail/jdom-interest/attachments/20030707/c547ee9d/attachment.htm


More information about the jdom-interest mailing list