2009-10-22 47 views
0

我有一個消息,它看起來像這樣的例子,但也有許多包含在其內更發票:BizTalk中的XPath返回串聯的字符串值。想元素和值

<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> 

所有我想要做的就是從使用XPath原始消息二號發票

這裏是我的Xpath:

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

全部返回,雖然在實際的字符串值連接到一起,像這樣:

13113400055152CUSNAME22S1512.77S151.92 

我想要的是元素標籤,所以它可以放入一個新的單一的發票消息。這是我期望得到的:

<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> 

我在做什麼錯?

回答

0

您的XPath是正確的;您的問題可能是您要求提供XML數據的方式;例如,在C#中,如果我運行XPath並請求.InnerText屬性,則會得到相同的僞造結果;但是,如果我將這個結果作爲XmlElement,我可以正確處理它。

HTH

1

我找到了解決問題的辦法。這很簡單。

它關注使用的XPath表達式。

與其說

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

省略字符串和值一起返回自己的元素。

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