1

I have following as a string and I want to get values from it like response code and response message how I can get that

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tns="https://exa.org/UpdateOrder/">
<soapenv:Body>
<tns:UpdateResponse xmlns="https://exa.org/UpdateOrder/">
<tns:responseCode>0</tns:responseCode>
<tns:responseMessage/>
</tns:UpdateResponse>
</soapenv:Body>
</soapenv:Envelope>
1
  • Use the DOM parser that's built into the JDK. Commented Jul 7, 2017 at 17:09

1 Answer 1

3

The standard scala xml library could make short work of it: The standard Scala XML library

Check out scala String to scala.xml.Elem to convert the string to an scala xml element.
Then you can navigate and parse the xml tree using xpath like sequences in the scala xml library. Something like this:

val xmlNode = scala.xml.XML.loadString(string)
val responseCode = (xmlNode \ "Body" \ "UpdateResponse" \ "responseCode").text
Sign up to request clarification or add additional context in comments.

1 Comment

I edited my answer. There was a typo with capitalization on "ResponseCode".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.