This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Creating JDOM Document from a String

 
John Fairbairn
Ranch Hand
Posts: 31
  • 0
  • 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
  • 0
  • 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
  • 0
  • 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: 20187
26
MySQL Database
  • 0
  • 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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic