aspose file tools*
The moose likes XML and Related Technologies and the fly likes How to convert String of XML elements into  Document Object Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "How to convert String of XML elements into  Document Object " Watch "How to convert String of XML elements into  Document Object " New topic
Author

How to convert String of XML elements into Document Object

Nilesh Raje
Ranch Hand

Joined: Aug 02, 2005
Posts: 153
Hi there,

I have written a parser which can parse a xml document using the following way.

xmlDoc = new SAXBuilder().build(eventConfigFile);

where eventConfigFile is my XML file . This parser successfully parses a XML document.

Now here is my problem. In real world this input would not be a XML file. it would be a one continous String with the contents of the XML file.
example:
"<DatahubRequest><Job>DHTest.Tibco</Job><ExternalID>12354</ExternalID><Source><Source_Location>RC_test</Source_Location><Source_Filename>DH_Test_in_20080811</Source_Filename><Source_Daydecrement>0</Source_Daydecrement></Source><Target><Target_Location>RC_test_11</Target_Location><Target_Filename>DH_Test_in_11111</Target_Filename><Target_Daydecrement>1</Target_Daydecrement></ Target><Target><Target_Location>RC_test_22</Target_Location><Target_Filename>DH_Test_in_2222</Target_Filename><Target_Daydecrement>1</Target_Daydecrement></Target></DatahubRequest>"

This string will be actually a pushed as a message on TIBCO EMS and i will pull it from there and read it as XML and extract the values and build my Objects.

How do i generate a Document Object out of this String which contains XML and parse it.


Thanks and Regards,<br />Nilesh<br />SCJP 1.4, SCWCD 1.4
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

You would have to look at the documentation of that SAXBuilder class and see what kind of inputs it can take. It isn't part of the standard Java API, so we (at least I) can't look at the documentation for you because we (at least I) don't know where it is.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to convert String of XML elements into Document Object