• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

XML STRING TO DOM DOCUMENT

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How do i convert XML string to a DOM document,and vice versa
please help???
 
Sheriff
Posts: 7001
6
Eclipse IDE Python C++ Debian Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Most Java DOM implementations will read and parse an XML doecument from any stream or reader, so why not just create a StringReader from the String, and parse that?
 
Frank Carver
Sheriff
Posts: 7001
6
Eclipse IDE Python C++ Debian Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"rkalidoss",
The Java Ranch has thousands of visitors every week, many with surprisingly similar names. To avoid confusion we have a naming convention, described at http://www.javaranch.com/name.jsp . We require names to have at least two words, separated by a space, and strongly recommend that you use your full real name. Please choose a new name which meets the requirements.
Thanks.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by rkalidoss:
How do i convert XML string to a DOM document,and vice versa
please help???


public void createDomObject(String xmlString)
{
DocumentBuilderFactory factory =
DocumentBuilderFactory.newInstance();
Document doc;
try {
DocumentBuilder builder = factory.newDocumentBuilder();
ByteArrayInputStream bais = new ByteArrayInputStream(xmlString.getBytes());
doc = builder.parse(bais);
System.out.println("getDoctype"+doc.getDoctype());
System.out.println("getDocumentElement"+doc.getDocumentElement());
System.out.println("getAttributes"+doc.getAttributes());
System.out.println("getChildNodes"+doc.getChildNodes());
}
catch (Exception ex) {
System.out.println("Exception occured");
ex.printStackTrace();
}
}
reply
    Bookmark Topic Watch Topic
  • New Topic