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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to retrieve DOM

 
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
hello ranchers,
Can you people help me ?
my problem is..........

i am going to do some online examination project.I want to implement AJAX model for my project.
i have created one servlet which fetches " Questions and answers" from Database and makes one XML document in the memory.
I want to retrieve this XML document in my java script code.


Can you people suggest me how to retrieve the DOM in my java Script code???


....................................Following is the code which generates XML document..........................

import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.io.DOMWriter;



public class DocGen
{

private org.dom4j.Document doc;
Element root;
Element child;
Element Ichild;

public org.w3c.dom.Document generateDoc() throws Exception{
doc = DocumentHelper.createDocument();

root=doc.addElement("Questions");
child= root.addElement("Question").addAttribute("id","1").addAttribute("text","Which of the following are valid java keywords?");
Ichild= child.addElement("Option").addText("while");
Ichild= child.addElement("Option").addText("if");
Ichild= child.addElement("Option").addText("goto");
Ichild= child.addElement("Option").addText("friend");

child= root.addElement("Question").addAttribute("id","2").addAttribute("text","which of the following are valid java access specifiers?");
Ichild= child.addElement("Option").addText("public");
Ichild= child.addElement("Option").addText("private");
Ichild= child.addElement("Option").addText("default");
Ichild= child.addElement("Option").addText("none");

DOMWriter writer = new DOMWriter(); /* this line is used to create W3C DOM object out of DOM4J DOM object */
return writer.write(this.doc);

}


}



..............................Following is the code which makes W3c DOM........................................................
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

import com.valueshore.xml.DocGen;

import org.dom4j.Document;

/**
*
* @author GSI
* @version
*/
public class EvaluationServlet extends HttpServlet {


protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException,Exception {

DocGen dg=new DocGen();
org.w3c.dom.Document doc=dg.generateDoc();
response.setContentType("text/xml");
PrintWriter out = response.getWriter();
out.close();
}


}
 
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
AJAX is discussed in the Javascript forum. Sounds like this is a good fit for that forum. Please continue the discussion in that forum. Thanks.

- m
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
looks like it was already post....Please do not cross post...we will move it to the right area!

https://coderanch.com/t/118427/HTML-JavaScript/Retrieve-DOM

Closing this one.

Eric
 
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic