Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Convert String to XML, then search for text

 
Matt Holloway
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Would it be ok to parse the XML string into a DOM tree and navigate to the parts you need using the DOM API?
 
Matt Holloway
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, I'll have a look at that.
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic