• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Creating JDOM Document from a String

 
John Fairbairn
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
You can have the ByteArrayInputStream :-
ByteArrayInputStream oByteArrayInputStream=new ByteArrayInputStream(String.getBytes());
 
Muhammad Farhan
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20739
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic