KBD

Keith Devens .com

Saturday, August 30, 2008 Flag waving
Don't panic. – Douglas Adams (The Hitchhiker's Guide to the Galaxy)
← JAXP docsBrandon Harper » Simple Integration of Ant and Subversion →

Daily link icon Wednesday, July 6, 2005

Java XML parsing monstrosity

Here's how to get a DOM Document from a String containing XML in Java:

try{
  Document d = DocumentBuilderFactory.newInstance().newDocumentBuilder()
    .parse(new InputSource(new StringReader(xml)));
}catch(Exception e){
  System.err.println("Couldn't create XML document from string: "+e.getMessage());
}

It's a little easier if you use the com.sun.xml.tree.XmlDocument class, but that's not standard.

← JAXP docsBrandon Harper » Simple Integration of Ant and Subversion →

Comments XML gif

Adam V. (http://adamv.com) wrote:

Gosh that's ugly.

Factory schmactory!

∴ Adam V. | 6-Jul-2005 5:18pm est | http://adamv.com | #7849

Keith (http://keithdevens.com/) wrote:

And AFAICT there's simply no way to create a Document directly. And all of these classes come from all different packages too, except for the first two.

Keith | 6-Jul-2005 9:42pm est | http://keithdevens.com/ | #7854

Feel free to post a comment below. Please see my comment policy.

Formatting Rules (No HTML):

  • **bold**, *italic*, _underlined_, --strikeout--
  • "text"="url" creates a link, and URLs are auto-highlighted
  • Blockquote: Like e-mail, begin paragraph with > (greater-than sign)
  • Lists: begin paragraph with *,-, or + (unordered), or # (ordered)
  • Code block: ?!code:language=perl|php|sql|javascript|etc.{\n}...{\n}?!/code

:
(will be your IP address if blank)
: (optional)
(Will not be shown on site)

: (optional)
:

August 2008
SunMonTueWedThuFriSat
 12
3456789
10111213141516
17181920212223
24252627282930
31 



RSS feed RSS feed for Keith's Weblog
Atom feed Atom feed for Keith's Weblog
Weblog archive
Recent comments
  on 2 posts

Recent comments XML

new⇒Girls, please don't get breast implants

http://when-3.ofawyib.net​http://girls-24.iniexka.net​http://swingers-4.emy...

Henry: Aug 30, 4:15am

new⇒Johnny Walker Blue Label

Wow, thanks for the scotch review​:D

Lagavulin and Laphroaig are​some of...

Keith: Aug 29, 3:35pm

Generated in about 0.135s.

(Used 8 db queries)

mobile phone