permaculture playing cards*
The moose likes XML and Related Technologies and the fly likes Creating JDOM Document from a String Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Creating JDOM Document from a String" Watch "Creating JDOM Document from a String" New topic
Author

Creating JDOM Document from a String

John Fairbairn
Ranch Hand

Joined: Jul 12, 2000
Posts: 31
How can I create a JDOM document from a String? I know you can use an InputStream, File, or URL object to create a JDOM document.
The only way I've got so far is to use the StringBufferInputStream which is deprecated. The api suggest using the StringReader object but class extends java.io.Reader not java.io.InputStream.

-- John
Jain Saurabh
Greenhorn

Joined: Sep 05, 2001
Posts: 26
Hi
You can have the ByteArrayInputStream :-
ByteArrayInputStream oByteArrayInputStream=new ByteArrayInputStream(String.getBytes());
Muhammad Farhan
Greenhorn

Joined: Apr 25, 2006
Posts: 1
Try this!

I tried this on a jsp page and it worked. Should work for you.

String XMLQuestions = request.getParameter("XMLQuestions");
SAXBuilder sxBuild = new SAXBuilder();
Document doc = sxBuild.build(new StringReader(XMLQuestions));
Element root = doc.getRootElement();
out.print(root.getContent());
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18657
    
    8

The "build(InputSource)" method is the one you want. Take a moment to inspect the constructors of org.xml.sax.InputSource and you'll see what I mean.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Creating JDOM Document from a String