File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes XML and Related Technologies and the fly likes Converting String to XML Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of RabbitMQ in Depth this week in the Open Source forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Converting String to XML" Watch "Converting String to XML" New topic

Converting String to XML

Abiodun Adisa
Ranch Hand

Joined: Jan 17, 2002
Posts: 495
I am passing a a full XML representation as a string between two programs, Please how steps do i need to "cast" the String to an XML Element
Dan Walin
Ranch Hand

Joined: Nov 11, 2003
Posts: 109
When you say "cast" it implies that an xml element is a java type. I may be wrong but, in my experience, I always create an XML just like you'd create a String (appending tags and values as needed). I usually have all the values as fields in a class (CMRAll in my example) so I can loop through all the fields to create the element names and values using the Class class in a method I call "xmlIt". The result is a String with the entire xml structure, like this:

I'm willing to listen to someone with a better idea since I am relatively new to creating xml from my code.
Hendrik Louw

Joined: Mar 01, 2007
Posts: 5
Have a look at JDom.
It's a very simple XML DOM API (Man that's a lot af TLA's )
Paul Clapham

Joined: Oct 14, 2005
Posts: 19552

You want to parse that String into a DOM, let's say?
I agree. Here's the link:
subject: Converting String to XML