aspose file tools*
The moose likes XML and Related Technologies and the fly likes How to pass a parsed XML Document object from servlet to JSP?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "How to pass a parsed XML Document object from servlet to JSP??" Watch "How to pass a parsed XML Document object from servlet to JSP??" New topic
Author

How to pass a parsed XML Document object from servlet to JSP??

Ray Smilgius
Ranch Hand

Joined: Jan 29, 2001
Posts: 120
I need to pass a Document Object from servlet to JSP:
I basically parse the input Stream into a doc such as::
InputStream in = urlConn.getInputStream();
DocumentBuilderFactory dbf=DocumentBuilderFactory.newInstance();
DocumentBuilder db=dbf.newDocumentBuilder();
Document doc = db.parse(in);
System.out.println("my doc "+ doc.toString()); // this gives me null???any ideas why?
I need to pass doc to template.jsp and to process the doc on the template.jsp
Thanks in advance

------------------
Sun Certified Java Programmer
Sun Certified Java Developer
I-Net Certified
A+ Certified
Network+ Certified
MCP

SCJO, SCJD, SCWCD, I-Net+, A+, Network+, MCSD, MCDBA, MCP, MCT
David Kane
Ranch Hand

Joined: Sep 20, 2001
Posts: 65
Here's a snippet of code from another program that I think does what you are looking for, perhaps it would be a useful example for you.
StringBuffer buffer = null;
parser.startDocument();
Document document = parser.getDocument();
NewsItem currentNewsItem = null;
NewsItemBuilder currentNewsItemBuilder = new NewsItemBuilder() ;
Node currentNewsItemNode = null;
currentNewsItem = (NewsItem)iterator.next();
currentNewsItemBuilder.setNewsItem(currentNewsItem);
currentNewsItemNode = currentNewsItemBuilder.getNewsItemNode(document);
document.appendChild(currentNewsItemNode);
OutputFormat of = new OutputFormat("XML","UTF-8",false);
StringWriter xmlData = new StringWriter();
XMLSerializer serializer = new XMLSerializer(xmlData,of);
serializer.serialize(document);
buffer = xmlData.getBuffer();
xmlItems[index] = buffer.toString();
Dave
------------------
David Kane
david_kane@houseofyin.com
Author of Software Architecture: Organizational Principles and Patterns
http://www.vraps.com
http://www.houseofyin.com


David Kane<BR> <A HREF="mailto:david_kane@houseofyin.com" rel="nofollow">david_kane@houseofyin.com</A> <BR>Author of <A HREF="http://www.amazon.com/exec/obidos/ASIN/0130290327/ref=ase_electricporkchop/103-0514572-3811868" TARGET=_blank rel="nofollow">Software Architecture: Organizational Principles and Patterns</A><BR><A HREF="http://www.vraps.com" TARGET=_blank rel="nofollow">http://www.vraps.com</A><BR><A HREF="http://www.houseofyin.com" TARGET=_blank rel="nofollow">http://www.houseofyin.com</A>
Ray Smilgius
Ranch Hand

Joined: Jan 29, 2001
Posts: 120
Thanks dave I will look over this code and I will get back to you.
Thanks in Advance
------------------
Sun Certified Java Programmer
Sun Certified Java Developer
I-Net Certified
A+ Certified
Network+ Certified
MCP
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to pass a parsed XML Document object from servlet to JSP??
 
Similar Threads
Can I load a xml string versus reading a file
Can and How do you pass a Document Object from servlet to a JSP
trouble passing info from servlet to jsp
Passing Document from servlet to JSP see code
need to get response xml string back from servlet to jsp page