0

I'm calling a soap webservice from my java application. I get response and I want to parse it and get data. The problem is that field <tranData>, contains structure with &gt;&lt; instead of <>. How can I parse this document to get data from field <tranData>?

This is response structure:

<response>
<Portfolio>
    <ID>1</ID>
    <holder>2</holder>
 </Portfolio>
<tranData>     &lt;responseOne&gt;&lt;header&gt;&lt;code&gt;1&lt;/code&gt;&lt;/header&gt;&lt;/responseOne&gt;</tranData>

Please remember that, this is only a example of response, and the amount of data will be much bigger, so the solution should be fast.

Thomas Fritsch
  • 9,639
  • 33
  • 37
  • 49
franczez
  • 63
  • 1
  • 1
  • 7
  • Try having a look at [this answer to a SO question](https://stackoverflow.com/a/599696/3690454). I think it could solve your issue. – Kizivat Oct 19 '18 at 12:42
  • Do you own the webservice? If you do then first of all you must send the data correctly so the client wouldnt have problem reading it. If you have no access the only way I think you can do is getting the tranData innerText and then replace < for "<" and > for ">" then you can simply create the XML Object for access it. – Brank Victoria Oct 19 '18 at 12:42
  • @Brank Victoria it is an external service and it is a correct response from it. Sure I can replace &lt and &gt but performance of this operation will be really low... – franczez Oct 19 '18 at 12:50

1 Answers1

0

What you show us is the actual document as it is received over the wire, right? So <tranData> contains an XML string that has been escaped to not interfere with the markup of the rest of the containing document.

When you read the content of the <tranData> element, the XML processor will 'unescape' the string and give you the 'original' value:

<responseOne><header><code>1</code></header></responseOne>

What you do with that value is a different story. You can parse it as yet another XML document and retrieve the value of the <code> element, or just pass the string along to some other processing step.

forty-two
  • 12,204
  • 2
  • 26
  • 36