开发者

XPath in BizTalk returns concatenated string values. Want Elements AND Values

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>
开发者_C百科</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?


I found the solution to the problem. It was very simple.

It concernes the XPath expression being used.

Instead of saying

msgInvoice = xpath(msgInvoicesEnvelope, "string  (//ns1:InvoicesEnvelope/Invoices/ns0:Invoice[position() = 2])”);

Omit the string and the values along with their elements are returned.

msgInvoice = xpath(msgInvoicesEnvelope, "//ns1:InvoicesEnvelope/Invoices/ns0:Invoice[position() = 2]”);


Your XPath is right; your problem is probably way you're asking for XML data;

For instance, in C#, if I run your XPath and ask for .InnerText property, I'll get same bogus result; but, if I take that result as a XmlElement I can handle it correctly.

HTH

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜