NIFI 读取 XML 节点数值

huangapple go评论59阅读模式
英文:

NIFI Reading XML node value

问题

我需要读取节点值"ReferenceDocumentNumber",其值为"SI-000000614"。我正在使用Nifi中的EvaluateXpath处理器。我的设置如下图所示:

NIFI 读取 XML 节点数值

我甚至尝试使用/@ReferenceDocument,但未能获取节点值。请在这里提供帮助。

英文:

I have the following xml:

<?xml version="1.0" encoding="UTF-8"?><ns1:SalesOrderMessages mlns:ns1="http://corpintra.net/pi/CBFC_GLOBAL_SAP_APPL/SalesOrder" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
         <SalesOrder>
            <MessageProcessingInformation>
               <SendingSystemID>SMS_0175</SendingSystemID>
            </MessageProcessingInformation>
            <Header>
               <SalesDocumentType>YPO0</SalesDocumentType>
               <SalesOrganization>7002</SalesOrganization>
               <DistributionChannel>00</DistributionChannel>
               <RequestedDeliveryDate>2023-06-15</RequestedDeliveryDate>
               <CustomerPurchaseOrderDate>2023-06-15</CustomerPurchaseOrderDate>
               <Incoterms1>EXW</Incoterms1>
               <Incoterms2>Ex Works</Incoterms2>
               <PaymentTerms>E007</PaymentTerms>
               <CustomerPurchaseOrderNumber>990831 </CustomerPurchaseOrderNumber>
               <ReferenceDocumentNumber>SI-000000614</ReferenceDocumentNumber>
               <ServicesRenderedDate>2023-06-15</ServicesRenderedDate>
               <LogisticData>
                  <SourceReferenceDocumentNumber>SI-000000614</SourceReferenceDocumentNumber>
                  <SourceSalesOrderNumber>SO-000050562</SourceSalesOrderNumber>
               </LogisticData>
            </Header>
            <Items>
               <ItemNumber>10</ItemNumber>
                   ............

I need to read the node value "ReferenceDocumentNumber", which is "SI-000000614"

I am using EvaluateXpath processor in Nifi. And my setting is attached in the imageNIFI 读取 XML 节点数值

I had even tried with /@ReferenceDocument. But not getting the node value. Please help here.

答案1

得分: 0

你错过了根元素 ns1:SalesOrderMessages。以下是适用于我的部分:

输入

<?xml version="1.0" encoding="UTF-8"?>
<ns1:SalesOrderMessages mlns:ns1="http://corpintra.net/pi/CBFC_GLOBAL_SAP_APPL/SalesOrder" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
         <SalesOrder>
            <MessageProcessingInformation>
               <SendingSystemID>SMS_0175</SendingSystemID>
            </MessageProcessingInformation>
            <Header>
               <SalesDocumentType>YPO0</SalesDocumentType>
               <SalesOrganization>7002</SalesOrganization>
               <DistributionChannel>00</DistributionChannel>
               <RequestedDeliveryDate>2023-06-15</RequestedDeliveryDate>
               <CustomerPurchaseOrderDate>2023-06-15</CustomerPurchaseOrderDate>
               <Incoterms1>EXW</Incoterms1>
               <Incoterms2>Ex Works</Incoterms2>
               <PaymentTerms>E007</PaymentTerms>
               <CustomerPurchaseOrderNumber>990831 </CustomerPurchaseOrderNumber>
               <ReferenceDocumentNumber>SI-000000614</ReferenceDocumentNumber>
               <ServicesRenderedDate>2023-06-15</ServicesRenderedDate>
               <LogisticData>
                  <SourceReferenceDocumentNumber>SI-000000614</SourceReferenceDocumentNumber>
                  <SourceSalesOrderNumber>SO-000050562</SourceSalesOrderNumber>
               </LogisticData>
            </Header>
</SalesOrder>
</ns1:SalesOrderMessages>

XPath 表达式

/*:SalesOrderMessages/SalesOrder/Header/ReferenceDocumentNumber

//ReferenceDocumentNumber

输出

SI-000000614
英文:

You missed the root element ns1:SalesOrderMessages. This works for me:

Input

<?xml version="1.0" encoding="UTF-8"?>
<ns1:SalesOrderMessages mlns:ns1="http://corpintra.net/pi/CBFC_GLOBAL_SAP_APPL/SalesOrder" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
         <SalesOrder>
            <MessageProcessingInformation>
               <SendingSystemID>SMS_0175</SendingSystemID>
            </MessageProcessingInformation>
            <Header>
               <SalesDocumentType>YPO0</SalesDocumentType>
               <SalesOrganization>7002</SalesOrganization>
               <DistributionChannel>00</DistributionChannel>
               <RequestedDeliveryDate>2023-06-15</RequestedDeliveryDate>
               <CustomerPurchaseOrderDate>2023-06-15</CustomerPurchaseOrderDate>
               <Incoterms1>EXW</Incoterms1>
               <Incoterms2>Ex Works</Incoterms2>
               <PaymentTerms>E007</PaymentTerms>
               <CustomerPurchaseOrderNumber>990831 </CustomerPurchaseOrderNumber>
               <ReferenceDocumentNumber>SI-000000614</ReferenceDocumentNumber>
               <ServicesRenderedDate>2023-06-15</ServicesRenderedDate>
               <LogisticData>
                  <SourceReferenceDocumentNumber>SI-000000614</SourceReferenceDocumentNumber>
                  <SourceSalesOrderNumber>SO-000050562</SourceSalesOrderNumber>
               </LogisticData>
            </Header>
</SalesOrder>
</ns1:SalesOrderMessages>

Xpath Expression

/*:SalesOrderMessages/SalesOrder/Header/ReferenceDocumentNumber

or

//ReferenceDocumentNumber

Output

SI-000000614

huangapple
  • 本文由 发表于 2023年6月15日 17:42:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/76481202.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定