Parsing an xml embedded within another xml using XPath Spring
<p>I'm parsing an xml String using the 'evaluate' function provided by Xpath to read the contents embedded within specific tags in the xml. But i'm having trouble while trying to parse an xml which is embeded within a set of tags which i want to parse.</p>

<pre><code>&lt;Channel&gt;
&lt;channelId&gt;SD0987&lt;/channelId&gt;
  &lt;parameters&gt;
&lt;param&gt;org.springframework.messaging.MessageHandlingException: HTTP request execution failed for URI [https://nike-dev.coupahost.com/api/suppliers?return_object=limited]; nested exception is org.springframework.web.client.HttpClientErrorException: 400 Bad Request&lt;/param&gt;
&lt;param&gt;&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;errors&gt;
 &lt;error&gt;
&lt;![CDATA[Unable to find valid PaymentTerm record for payment_term with keys    {"code"=&gt;"9999"}. Possible keys are ["id", "code"]. Please verify your xml.]]&gt;
&lt;/error&gt;
&lt;/errors&gt;
&lt;/param&gt;
&lt;param&gt;6-5100&lt;/param&gt;
&lt;param&gt;&lt;?xml version="1.0" encoding="UTF-8"?&gt;&lt;supplier&gt;&lt;name&gt;SuTestVDR008-6-5100&lt;/name&gt;&lt;display-name&gt;SuTestVDR008-6 (SANDALS) - VAT Registration Number - Indirect Europe - INACTIVE&lt;/display-name&gt;&lt;status&gt;active&lt;/status&gt;&lt;deleted type="boolean"&gt;true&lt;/deleted&gt;&lt;vendor-account-group-code&gt;1001&lt;/vendor-account-group-code&gt;&lt;vendor-number&gt;SuTestVDR008-6&lt;/vendor-number&gt;&lt;on-hold type="boolean"&gt;false&lt;/on-hold&gt;&lt;language-code&gt;E&lt;/language-code&gt;&lt;purchase-organization-code&gt;5100&lt;/purchase-organization-code&gt;&lt;group-key&gt;1234&lt;/group-key&gt;&lt;vendor-partner-type-code&gt;Z4&lt;/vendor-partner-type-code&gt;&lt;currency-code&gt;EUR&lt;/currency-code&gt;&lt;primary-address&gt;&lt;street1&gt;@@@@ JIU BI VILLAGE&lt;/street1&gt;&lt;street2&gt;77774&lt;/street2&gt;&lt;city&gt;GUANGZHOU CITY&lt;/city&gt;&lt;state&gt;190-Guangdong&lt;/state&gt;&lt;postal-code&gt;511480&lt;/postal-code&gt;&lt;country&gt;&lt;code&gt;CN&lt;/code&gt;&lt;/country&gt;&lt;/primary-address&gt;&lt;payment-term&gt;&lt;code&gt;9999&lt;/code&gt;&lt;/payment-term&gt;&lt;content-groups&gt;&lt;content-group&gt;&lt;name&gt;730_Company Code&lt;/name&gt;&lt;/content-group&gt;&lt;/content-groups&gt;&lt;po-method&gt;prompt&lt;/po-method&gt;&lt;invoice-matching-level&gt;3-way&lt;/invoice-matching-level&gt;&lt;/supplier&gt;&lt;/param&gt;
&lt;/parameters&gt;
&lt;/Channel&gt;
</code></pre>

<p>In the above xml sample, i need to read and retrieve everything that is within the tags "param".
Currently, i'm first getting a count of the param tags and then looping thru them to get the data within the tags -</p>

<pre><code>    paramCount = XPathUtils.evaluate(originalPayload,"count(/Channel/parameters/param)",XPathUtils.STRING);    
    for(int i=1;i&lt;=pCount;i++){
          pList.add(XPathUtils.evaluate(originalPayload, "/Channel/parameters/param[" +i+ "]",XPathUtils.STRING)
            }
</code></pre>

<p>This works fine with other xmls but not with the sample given above. I get the below error - </p>

<pre><code>"[Fatal Error] :5:17:The processing instruction target matching "[xX][mM][lL]" is not allowed."
</code></pre>

<p>If i remove the part "?xmlversion="1.0" encoding="UTF-8"?
it parses the tags but the output is - </p>

<pre><code>org.springframework.messaging.MessageHandlingException: HTTP request execution failed for URI [https://nike-dev.coupahost.com/api/suppliers?return_object=limited]; nested exception is org.springframework.web.client.HttpClientErrorException: 400 Bad Request


Unable to find valid PaymentTerm record for payment_term with keys {"code"=&gt;"9999"}. Possible keys are ["id", "code"]. Please verify your xml.



6-5100
SuTestVDR008-6-5100SuTestVDR008-6 (SANDALS) - VAT Registration Number - Indirect Europe - INACTIVEactivetrue1001SuTestVDR008-6falseE51001234Z4EUR@@@@ JIU BI VILLAGE77774GUANGZHOU CITY190-Guangdong511480CN9999730_Company Codeprompt3-way
</code></pre>

<p>So as you can see, it just captured the content within the various tags and printed it.
My ask is to print all the text in between the </p>

<pre><code>&lt;param &gt;
</code></pre>

<p>tags as is with all the indentation in place.</p>

<p>So the output expected is  - </p>

<pre><code>org.springframework.messaging.MessageHandlingException: HTTP request execution failed for URI [https://nike-dev.coupahost.com/api/suppliers?return_object=limited]; nested exception is org.springframework.web.client.HttpClientErrorException: 400 Bad Request
&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;errors&gt;
&lt;error&gt;
&lt;![CDATA[Unable to find valid PaymentTerm record for payment_term with keys {"code"=&gt;"9999"}. Possible keys are ["id", "code"]. Please verify your xml.]]&gt;
&lt;/error&gt;
&lt;/errors&gt;
6-5100
&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;supplier&gt;&lt;name&gt;SuTestVDR008-6-5100&lt;/name&gt;&lt;display-name&gt;SuTestVDR008-6 (SANDALS) - VAT Registration Number - Indirect Europe - INACTIVE&lt;/display-name&gt;&lt;status&gt;active&lt;/status&gt;&lt;deleted type="boolean"&gt;true&lt;/deleted&gt;&lt;vendor-account-group-code&gt;1001&lt;/vendor-account-group-code&gt;&lt;vendor-number&gt;SuTestVDR008-6&lt;/vendor-number&gt;&lt;on-hold type="boolean"&gt;false&lt;/on-hold&gt;&lt;language-code&gt;E&lt;/language-code&gt;&lt;purchase-organization-code&gt;5100&lt;/purchase-organization-code&gt;&lt;group-key&gt;1234&lt;/group-key&gt;&lt;vendor-partner-type-code&gt;Z4&lt;/vendor-partner-type-code&gt;&lt;currency-code&gt;EUR&lt;/currency-code&gt;&lt;primary-address&gt;&lt;street1&gt;@@@@ JIU BI VILLAGE&lt;/street1&gt;&lt;street2&gt;77774&lt;/street2&gt;&lt;city&gt;GUANGZHOU CITY&lt;/city&gt;&lt;state&gt;190-Guangdong&lt;/state&gt;&lt;postal-code&gt;511480&lt;/postal-code&gt;&lt;country&gt;&lt;code&gt;CN&lt;/code&gt;&lt;/country&gt;&lt;/primary-address&gt;&lt;payment-term&gt;&lt;code&gt;9999&lt;/code&gt;&lt;/payment-term&gt;&lt;content-groups&gt;&lt;content-group&gt;&lt;name&gt;730_Company Code&lt;/name&gt;&lt;/content-group&gt;&lt;/content-groups&gt;&lt;po-method&gt;prompt&lt;/po-method&gt;&lt;invoice-matching-level&gt;3-way&lt;/invoice-matching-level&gt;&lt;/supplier&gt;
</code></pre>

<p>Any ideas?</p>