• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Creating JDOM Document from a String

 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
You can have the ByteArrayInputStream :-
ByteArrayInputStream oByteArrayInputStream=new ByteArrayInputStream(String.getBytes());
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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());
 
Marshal
Posts: 28296
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 think she's lovely. It's this tiny ad that called her crazy:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic