aspose file tools*
The moose likes XML and Related Technologies and the fly likes Convert String to XML, then search for text Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Convert String to XML, then search for text" Watch "Convert String to XML, then search for text" New topic
Author

Convert String to XML, then search for text

Matt Holloway
Ranch Hand

Joined: Oct 16, 2003
Posts: 53
I have a SOAP message that comes back from an external system to my Java class as a String. I need to convert this to XML, then search for text in certain elements. Anybody have quick method, or point me to a tutorial for this? Here is a sample of what I'm trying to do:
String Returned

What I need

Thanks.
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Would it be ok to parse the XML string into a DOM tree and navigate to the parts you need using the DOM API?


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Matt Holloway
Ranch Hand

Joined: Oct 16, 2003
Posts: 53
That would work. Really, I just want an easy search and grab method, rather than running through a String object searching for text and grabbing data, it would be nice to just grab values of tags.
Matt Holloway
Ranch Hand

Joined: Oct 16, 2003
Posts: 53
p.s. : please ignore the fact that the XML above is malformed, there shouldn't be a closing </faultcode> at the bottom as that tag is closed on the same line as it is declared.
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
You might also benefit from using XPath to pick the parts you want. Jaxen is an open source XPath library you could probably use for the job.
Matt Holloway
Ranch Hand

Joined: Oct 16, 2003
Posts: 53
Thanks, I'll have a look at that.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Convert String to XML, then search for text