I have a message which looks like this for example, but could have many more invoices contained within it:
<ns1:InvoicesEnvelope xmlns:ns1="http://Test.Schemas.InvoiceEnvelope_1"xmlns:ns0="http://Test.Schemas.Invoices">
<Invoices>
<ns0:Invoice>
<Header>
<BatchID>1311</BatchID>
<InvoiceNo>3400055151</InvoiceNo>
<CustomerName>CUSNAME1</CustomerName>
<TotalInvoiceLines>2</TotalInvoiceLines>
</Header>
<Lines>
<Line>
<TaxCode>S15</TaxCode>
<InvoiceAmt>12.77</InvoiceAmt>
</Line>
<Line>
<TaxCode>S15</TaxCode>
<InvoiceAmt>1.92</InvoiceAmt>
</Line>
</Lines>
</ns0:Invoice>
<ns0:Invoice>
<Header>
<BatchID>1311</BatchID>
<InvoiceNo>3400055152</InvoiceNo>
<CustomerName>CUSNAME2</CustomerName>
<TotalInvoiceLines>2</TotalInvoiceLines>
</Header>
<Lines>
<Line>
<TaxCode>S15</TaxCode>
<InvoiceAmt>12.77</InvoiceAmt>
</Line>
<Line>
<TaxCode>S15</TaxCode>
<InvoiceAmt>1.92</InvoiceAmt>
</Line>
</Lines>
</ns0:Invoice>
</Invoices>
</ns1:InvoicesEnvelope>
All I want to do is get the 2nd Invoice from the original message using xpath
Here is my Xpath:
msgInvoice = xpath(msgInvoicesEnvelope, "string (//ns1:InvoicesEnvelope/Invoices/ns0:Invoice[position() = 2])”);
All it returns though are the actual string values concatenated together like so:
13113400055152CUSNAME22S1512.77S151.92
What I want is the element tags aswell so it can be put into a new single invoice message. This is what I expect to get:
<ns0:Invoice>
<Header>
<BatchID>1311</BatchID>
<InvoiceNo>3400055152</InvoiceNo>
<CustomerName>CUSNAME2</CustomerName>
<TotalInvoiceLines>2</TotalInvoiceLines>
</Header>
<Lines>
<Line>
<TaxCode>S15</TaxCode>
<InvoiceAmt>12.77</InvoiceAmt>
</Line>
<Line>
<TaxCode>S15</TaxCode>
<InvoiceAmt>1.92</InvoiceAmt>
</Line>
</Lines>
</ns0:Invoice>
</Invoices>
What am I doing wrong? This has been bugging me now for nearly 2 days…..