Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
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
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Creating JDOM Document from a String" Watch "Creating JDOM Document from a String" New topic

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 not

-- John
Jain Saurabh

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

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 = StringReader(XMLQuestions));
Element root = doc.getRootElement();
Paul Clapham

Joined: Oct 14, 2005
Posts: 19739

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:
subject: Creating JDOM Document from a String
It's not a secret anymore!