participate


Java 2 Software Development Kit (J2SE SDK) - Convert XML string into DOM
<<   Back to Forum  |   Give us Feedback
This topic has 6 replies on 1 page.
xyoon
Posts:48
Registered: 6/11/03
Convert XML string into DOM   
Aug 6, 2004 1:08 AM

 
Hi all,

I have a question here regarding converting XML string into a DOM document.
How can I do this in Java?

The Document.Parse() methods do not have one that takes in String as its parameter.
I'm not sure what is the best way to do this in Java.

Any help is greatly appreciated.
Thank you in advance.


regards,
Sean
 
Martin3
Posts:561
Registered: 4/28/98
Re: Convert XML string into DOM   
Aug 6, 2004 5:02 AM (reply 1 of 6)  (In reply to original post )

 
See

http://cvs.sourceforge.net/viewcvs.py/mathml-x/mathml-x/examples/graph/src/com/neuralworks/graph/MixedMain.java?rev=1.1&view=markup

Check the internalXMLDocument object creation. The code prepares an InputStream from a String of mathml and

http://java.sun.com/j2se/1.5.0/docs/api/javax/xml/parsers/DocumentBuilder.html#parse(java.io.InputStream)
 
dvohra09
Posts:3,591
Registered: 4/4/01
Re: Convert XML string into DOM   
Aug 7, 2004 8:35 AM (reply 2 of 6)  (In reply to original post )

 

Convert XML String to Document with StringReader.

String xmlString; 
DocumentBuilderFactory factory =
            DocumentBuilderFactory.newInstance();
       
            DocumentBuilder builder = factory.newDocumentBuilder();
   Document         document = builder.parse(new InputSource(new StringReader(xmlString)));
 
xyoon
Posts:48
Registered: 6/11/03
Re: Convert XML string into DOM   
Aug 7, 2004 11:41 PM (reply 3 of 6)  (In reply to #2 )

 
Hi dvohra09,

That's exactly what I want.
Thank you so much :)


regards,
Sean
 
Martin3
Posts:561
Registered: 4/28/98
Re: Convert XML string into DOM   
Aug 9, 2004 6:07 AM (reply 4 of 6)  (In reply to #3 )

 
dvohra09,
That is a very neat and efficient way. I'll switch my stuff to what you presented too. Thanks!
 
abhi.1289
Posts:1
Registered: 7/13/06
Re: Convert XML string into DOM   
Jul 13, 2006 2:47 AM (reply 5 of 6)  (In reply to #2 )

 
Hai,
Thx. i was having the same problem i got the code and its working fine
 
JavaSUN
Posts:1
Registered: 5/13/07
Re: Convert XML string into DOM   
May 13, 2007 7:44 PM (reply 6 of 6)  (In reply to #5 )

 
Hi,
Thanks a lot for the reply. Its really helpful.
 
This topic has 6 replies on 1 page.
Back to Forum
 
Read the Developer Forums Code of Conduct

Click to email this message Email this Topic

Edit this Topic
  
 
 
Forums Statistics
    Users Online : 25
  • Guests : 132

About Sun forums
  • Oracle Forums is a large collection of user generated discussions. It is here to help you ask questions, find answers, and participate in discussions.

    Check out our guide on Getting started with Oracle Forums for a full walkthrough of how to best leverage the benefits of this community.

Powered by Jive Forums