如何EDI标准文件转换为自定义XML?
今天分享EDI报文转换,主要围绕X12标准 850 采购订单展开介绍。
以下方案,源代码分享给大家。
https://www.kasoftware.com/translation/edi_xml_convert_sample.html
实现EDI转自定义XML,可以分两步完成。
- 根据国际标准,先将EDI文件转换为标准的XML文件;
- 通过脚本,实现标准XML与自定义XML的关系映射。
以850采购订单为例,源文件如下:
ISA*00* *00* *ZZ*WAYNE_TECH *ZZ*ACME *160609*1330*U*00401*000000007*0*T*>~
GS*PO*WAYNE_TECH*ACME*20160609*1330*7*T*004010~
ST*850*0001~
BEG*00*DS*0476696888**20150708~
REF*SB*ZZ11~
REF*6P*ZZ~
REF*8M*0056~
REF*CR*1070335099~
REF*CO*7109790082~
PER*CN*ACME, Inc.*TE*(555) 555-5555~
CSH*SC~
SAC*C*ZZZZ**********06~
TD5*Z*2*123456~
N9*PD*ZCOF~
MSG*Thanks!~
N1*BY*Wayne Tech*92*5601~
N2*Wayne Tech*~
N3*125 WayneHigh Road.~
N1*EN*ACME, Inc.~
N1*ST*Wayne Tech Plant 1*92*0000505462~
N2*Wayne Tech Plant 1*~
N3*100 Wayne Ave.~
N4*Chapel Hill*MX*27514*US**~
PO1**500000*EA*495*TP*BP*337S3744*VP*422242224~
PID*F****500,000 red widgets****EN~
SCH*500000*EA***002*20180708~
PO1**100*EA*395*HP*BP*337S3745*VP*422242226~
PID*F****100 blue widgets****EN~
SCH*100*EA***002*20180708~
PO1**500*EA*210*TP*BP*337S3746*VP*422201210~
PID*F****AH-0310 red widgets****EN~
SCH*500*EA***002*20180708~
PO1**150*EA*350*TP*BP*337S3747*VP*422241452~
PID*F****F-100 blue widgets****EN~
SCH*100*EA***002*20180708~
PO1**500000*EA*495*TP*BP*337S3748*VP*422244512~
PID*F****HU-021 black widgets****EN~
SCH*500000*EA***002*20180708~
PO1**1500*EA*3000*HP*BP*337S3749*VP*422241023~
PID*F****100-20J widgets****EN~
SCH*100*EA***002*20180708~
CTT*6*500100~
SE*39*0001~
GE*1*7~
IEA*1*000000007~
先看转换标准XML的结果,内容看似很长,一半以上的内容都是注释,解释每个字段对应的业务含义,即便没有EDI规范,也可以快速了解该EDI文件都包含了哪些业务数据:
<Interchange Delimiters=":*. ^~" xmlns="http://www.rssbus.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Meta>
<!--Authorization Information Qualifier-->
<ISA01><!--No Authorization Information Present (No Meaningful Information in I02)-->00</ISA01>
<!--Authorization Information-->
<ISA02> </ISA02>
<!--Security Information Qualifer-->
<ISA03>00</ISA03>
<!--Security Information-->
<ISA04> </ISA04>
<!--Interchange ID Qualifier-->
<ISA05><!--Mutually Defined-->ZZ</ISA05>
<!--Interchange Sender ID-->
<ISA06>WAYNE_TECH </ISA06>
<!--Interchange ID Qualifier-->
<ISA07><!--Mutually Defined-->ZZ</ISA07>
<!--Interchange Receiver ID-->
<ISA08>ACME </ISA08>
<!--Interchange Date-->
<ISA09>160609</ISA09>
<!--Interchange Time-->
<ISA10>1330</ISA10>
<!--Interchange Control Standards Identifier-->
<ISA11>U</ISA11>
<!--Interchange Control Version Number Code-->
<ISA12><!--Standards Approved for Publication by ASC X12 Procedures Review Board through October 1997-->00401</ISA12>
<!--Inter Control Number-->
<ISA13>000000007</ISA13>
<!--Acknowlegment Requested Code-->
<ISA14>0</ISA14>
<!--Interchange Usage Indicator Code-->
<ISA15><!--Test Data-->T</ISA15>
<!--Component Element Separator-->
<ISA16>></ISA16>
</Meta>
<FunctionalGroup>
<Meta>
<!--Functional Identifier Code-->
<GS01><!--Purchase Order (850)-->PO</GS01>
<!--Application Sender's Code-->
<GS02>WAYNE_TECH</GS02>
<!--Application Receiver's Code-->
<GS03>ACME</GS03>
<!--Date-->
<GS04>20160609</GS04>
<!--Time-->
<GS05>1330</GS05>
<!--Group Control Number-->
<GS06>7</GS06>
<!--Responsible Agency Code-->
<GS07><!--Transportation Data Coordinating Committee (TDCC)-->T</GS07>
<!--Version / Release / Industry Identifier Code-->
<GS08><!--Standards Approved for Publication by ASC X12 Procedures Review Board through October 1997-->004010</GS08>
</Meta>
<TransactionSet>
<TX-00401-850 type="TransactionSet">
<Meta>
<!--Transaction Set Identifier Code-->
<ST01><!--Purchase Order-->850</ST01>
<!--Transaction Set Control Number-->
<ST02>0001</ST02>
</Meta>
<BEG type="Segment">
<!--Transaction Set Purpose Code-->
<BEG01><!--Original-->00</BEG01>
<!--Purchase Order Type Code-->
<BEG02><!--Dropship-->DS</BEG02>
<!--Purchase Order Number-->
<BEG03>0476696888</BEG03>
<!--Release Number-->
<BEG04 xsi:nil="true"/>
<!--Date-->
<BEG05>20150708</BEG05>
</BEG>
<REF type="Segment">
<!--Reference Identification Qualifier-->
<REF01><!--Sales Region Number-->SB</REF01>
<!--Reference Identification-->
<REF02>ZZ11</REF02>
</REF>
<REF type="Segment">
<!--Reference Identification Qualifier-->
<REF01><!--Group Number-->6P</REF01>
<!--Reference Identification-->
<REF02>ZZ</REF02>
</REF>
<REF type="Segment">
<!--Reference Identification Qualifier-->
<REF01><!--Originating Company Identifier-->8M</REF01>
<!--Reference Identification-->
<REF02>0056</REF02>
</REF>
<REF type="Segment">
<!--Reference Identification Qualifier-->
<REF01><!--Customer Reference Number-->CR</REF01>
<!--Reference Identification-->
<REF02>1070335099</REF02>
</REF>
<REF type="Segment">
<!--Reference Identification Qualifier-->
<REF01><!--Customer Order Number-->CO</REF01>
<!--Reference Identification-->
<REF02>7109790082</REF02>
</REF>
<PER type="Segment">
<!--Contact Function Code-->
<PER01><!--General Contact-->CN</PER01>
<!--Name-->
<PER02>ACME, Inc.</PER02>
<!--Communication Number Qualifier-->
<PER03><!--Telephone-->TE</PER03>
<!--Communication Number-->
<PER04>(555) 555-5555</PER04>
</PER>
<CSH type="Segment">
<!--Sales Requirement Code-->
<CSH01><!--Ship Complete-->SC</CSH01>
</CSH>
<SACLoop1 type="Loop">
<SAC type="Segment">
<!--Allowance or Charge Indicator-->
<SAC01>C</SAC01>
<!--Service, Promotion, Allowance, or Charge Code-->
<SAC02><!--Mutually Defined-->ZZZZ</SAC02>
<!--Agency Qualifier Code-->
<SAC03/>
<!--Agency Service, Promotion, Allowance, or Charge Code-->
<SAC04 xsi:nil="true"/>
<!--Amount-->
<SAC05 xsi:nil="true"/>
<!--Allowance/Charge Percent Qualifier-->
<SAC06/>
<!--Percent-->
<SAC07 xsi:nil="true"/>
<!--Rate-->
<SAC08 xsi:nil="true"/>
<!--Unit or Basis for Measurement Code-->
<SAC09/>
<!--Quantity-->
<SAC10 xsi:nil="true"/>
<!--Quantity-->
<SAC11 xsi:nil="true"/>
<!--Allowance or Charge Method of Handling Code-->
<SAC12><!--Charge to be Paid by Customer-->06</SAC12>
</SAC>
</SACLoop1>
<TD5 type="Segment">
<!--Routing Sequence Code-->
<TD501><!--Mutually Defined-->Z</TD501>
<!--Identification Code Qualifier-->
<TD502><!--Standard Carrier Alpha Code (SCAC)-->2</TD502>
<!--Identification Code-->
<TD503>123456</TD503>
</TD5>
<N9Loop1 type="Loop">
<N9 type="Segment">
<!--Reference Identification Qualifier-->
<N901><!--Promotion/Deal Number-->PD</N901>
<!--Reference Identification-->
<N902>ZCOF</N902>
</N9>
<MSG type="Segment">
<!--Free-Form Message Text-->
<MSG01>Thanks!</MSG01>
</MSG>
</N9Loop1>
<N1Loop1 type="Loop">
<N1 type="Segment">
<!--Entity Identifier Code-->
<N101><!--Buying Party (Purchaser)-->BY</N101>
<!--Name-->
<N102>Wayne Tech</N102>
<!--Identification Code Qualifier-->
<N103><!--Assigned by Buyer or Buyer's Agent-->92</N103>
<!--Identification Code-->
<N104>5601</N104>
</N1>
<N2 type="Segment">
<!--Name-->
<N201>Wayne Tech</N201>
</N2>
<N3 type="Segment">
<!--Address Information-->
<N301>125 WayneHigh Road.</N301>
</N3>
</N1Loop1>
<N1Loop1 type="Loop">
<N1 type="Segment">
<!--Entity Identifier Code-->
<N101><!--End User-->EN</N101>
<!--Name-->
<N102>ACME, Inc.</N102>
</N1>
</N1Loop1>
<N1Loop1 type="Loop">
<N1 type="Segment">
<!--Entity Identifier Code-->
<N101><!--Ship To-->ST</N101>
<!--Name-->
<N102>Wayne Tech Plant 1</N102>
<!--Identification Code Qualifier-->
<N103><!--Assigned by Buyer or Buyer's Agent-->92</N103>
<!--Identification Code-->
<N104>0000505462</N104>
</N1>
<N2 type="Segment">
<!--Name-->
<N201>Wayne Tech Plant 1</N201>
</N2>
<N3 type="Segment">
<!--Address Information-->
<N301>100 Wayne Ave.</N301>
</N3>
<N4 type="Segment">
<!--City Name-->
<N401>Chapel Hill</N401>
<!--State or Province Code-->
<N402>MX</N402>
<!--Postal Code-->
<N403>27514</N403>
<!--Country Code-->
<N404>US</N404>
</N4>
</N1Loop1>
<PO1Loop1 type="Loop">
<PO1 type="Segment">
<!--Assigned Identification-->
<PO101 xsi:nil="true"/>
<!--Quantity Ordered-->
<PO102>500000</PO102>
<!--Unit or Basis for Measurement Code-->
<PO103><!--Each-->EA</PO103>
<!--Unit Price-->
<PO104>495</PO104>
<!--Basis of Unit Price Code-->
<PO105><!--Price per Thousand-->TP</PO105>
<!--Product/Service ID Qualifier-->
<PO106><!--Buyer's Part Number-->BP</PO106>
<!--Product/Service ID-->
<PO107>337S3744</PO107>
<!--Product/Service ID Qualifier-->
<PO108><!--Vendor's (Seller's) Part Number-->VP</PO108>
<!--Product/Service ID-->
<PO109>422242224</PO109>
</PO1>
<PIDLoop1 type="Loop">
<PID type="Segment">
<!--Item Description Type-->
<PID01>F</PID01>
<!--Product/Process Characteristic Code-->
<PID02/>
<!--Agency Qualifier Code-->
<PID03/>
<!--Product Description Code-->
<PID04 xsi:nil="true"/>
<!--Description-->
<PID05>500,000 red widgets</PID05>
<!--Surface/Layer/Position Code-->
<PID06/>
<!--Source Subqualifier-->
<PID07 xsi:nil="true"/>
<!--Yes/No Condition or Response Code-->
<PID08/>
<!--Language Code-->
<PID09>EN</PID09>
</PID>
</PIDLoop1>
<SCHLoop1 type="Loop">
<SCH type="Segment">
<!--Quantity-->
<SCH01>500000</SCH01>
<!--Unit or Basis for Measurement Code-->
<SCH02><!--Each-->EA</SCH02>
<!--Entity Identifier Code-->
<SCH03/>
<!--Name-->
<SCH04 xsi:nil="true"/>
<!--Date/Time Qualifier-->
<SCH05><!--Delivery Requested-->002</SCH05>
<!--Date-->
<SCH06>20180708</SCH06>
</SCH>
</SCHLoop1>
</PO1Loop1>
<PO1Loop1 type="Loop">
<PO1 type="Segment">
<!--Assigned Identification-->
<PO101 xsi:nil="true"/>
<!--Quantity Ordered-->
<PO102>100</PO102>
<!--Unit or Basis for Measurement Code-->
<PO103><!--Each-->EA</PO103>
<!--Unit Price-->
<PO104>395</PO104>
<!--Basis of Unit Price Code-->
<PO105><!--Price per Hundred-->HP</PO105>
<!--Product/Service ID Qualifier-->
<PO106><!--Buyer's Part Number-->BP</PO106>
<!--Product/Service ID-->
<PO107>337S3745</PO107>
<!--Product/Service ID Qualifier-->
<PO108><!--Vendor's (Seller's) Part Number-->VP</PO108>
<!--Product/Service ID-->
<PO109>422242226</PO109>
</PO1>
<PIDLoop1 type="Loop">
<PID type="Segment">
<!--Item Description Type-->
<PID01>F</PID01>
<!--Product/Process Characteristic Code-->
<PID02/>
<!--Agency Qualifier Code-->
<PID03/>
<!--Product Description Code-->
<PID04 xsi:nil="true"/>
<!--Description-->
<PID05>100 blue widgets</PID05>
<!--Surface/Layer/Position Code-->
<PID06/>
<!--Source Subqualifier-->
<PID07 xsi:nil="true"/>
<!--Yes/No Condition or Response Code-->
<PID08/>
<!--Language Code-->
<PID09>EN</PID09>
</PID>
</PIDLoop1>
<SCHLoop1 type="Loop">
<SCH type="Segment">
<!--Quantity-->
<SCH01>100</SCH01>
<!--Unit or Basis for Measurement Code-->
<SCH02><!--Each-->EA</SCH02>
<!--Entity Identifier Code-->
<SCH03/>
<!--Name-->
<SCH04 xsi:nil="true"/>
<!--Date/Time Qualifier-->
<SCH05><!--Delivery Requested-->002</SCH05>
<!--Date-->
<SCH06>20180708</SCH06>
</SCH>
</SCHLoop1>
</PO1Loop1>
<PO1Loop1 type="Loop">
<PO1 type="Segment">
<!--Assigned Identification-->
<PO101 xsi:nil="true"/>
<!--Quantity Ordered-->
<PO102>500</PO102>
<!--Unit or Basis for Measurement Code-->
<PO103><!--Each-->EA</PO103>
<!--Unit Price-->
<PO104>210</PO104>
<!--Basis of Unit Price Code-->
<PO105><!--Price per Thousand-->TP</PO105>
<!--Product/Service ID Qualifier-->
<PO106><!--Buyer's Part Number-->BP</PO106>
<!--Product/Service ID-->
<PO107>337S3746</PO107>
<!--Product/Service ID Qualifier-->
<PO108><!--Vendor's (Seller's) Part Number-->VP</PO108>
<!--Product/Service ID-->
<PO109>422201210</PO109>
</PO1>
<PIDLoop1 type="Loop">
<PID type="Segment">
<!--Item Description Type-->
<PID01>F</PID01>
<!--Product/Process Characteristic Code-->
<PID02/>
<!--Agency Qualifier Code-->
<PID03/>
<!--Product Description Code-->
<PID04 xsi:nil="true"/>
<!--Description-->
<PID05>AH-0310 red widgets</PID05>
<!--Surface/Layer/Position Code-->
<PID06/>
<!--Source Subqualifier-->
<PID07 xsi:nil="true"/>
<!--Yes/No Condition or Response Code-->
<PID08/>
<!--Language Code-->
<PID09>EN</PID09>
</PID>
</PIDLoop1>
<SCHLoop1 type="Loop">
<SCH type="Segment">
<!--Quantity-->
<SCH01>500</SCH01>
<!--Unit or Basis for Measurement Code-->
<SCH02><!--Each-->EA</SCH02>
<!--Entity Identifier Code-->
<SCH03/>
<!--Name-->
<SCH04 xsi:nil="true"/>
<!--Date/Time Qualifier-->
<SCH05><!--Delivery Requested-->002</SCH05>
<!--Date-->
<SCH06>20180708</SCH06>
</SCH>
</SCHLoop1>
</PO1Loop1>
<PO1Loop1 type="Loop">
<PO1 type="Segment">
<!--Assigned Identification-->
<PO101 xsi:nil="true"/>
<!--Quantity Ordered-->
<PO102>150</PO102>
<!--Unit or Basis for Measurement Code-->
<PO103><!--Each-->EA</PO103>
<!--Unit Price-->
<PO104>350</PO104>
<!--Basis of Unit Price Code-->
<PO105><!--Price per Thousand-->TP</PO105>
<!--Product/Service ID Qualifier-->
<PO106><!--Buyer's Part Number-->BP</PO106>
<!--Product/Service ID-->
<PO107>337S3747</PO107>
<!--Product/Service ID Qualifier-->
<PO108><!--Vendor's (Seller's) Part Number-->VP</PO108>
<!--Product/Service ID-->
<PO109>422241452</PO109>
</PO1>
<PIDLoop1 type="Loop">
<PID type="Segment">
<!--Item Description Type-->
<PID01>F</PID01>
<!--Product/Process Characteristic Code-->
<PID02/>
<!--Agency Qualifier Code-->
<PID03/>
<!--Product Description Code-->
<PID04 xsi:nil="true"/>
<!--Description-->
<PID05>F-100 blue widgets</PID05>
<!--Surface/Layer/Position Code-->
<PID06/>
<!--Source Subqualifier-->
<PID07 xsi:nil="true"/>
<!--Yes/No Condition or Response Code-->
<PID08/>
<!--Language Code-->
<PID09>EN</PID09>
</PID>
</PIDLoop1>
<SCHLoop1 type="Loop">
<SCH type="Segment">
<!--Quantity-->
<SCH01>100</SCH01>
<!--Unit or Basis for Measurement Code-->
<SCH02><!--Each-->EA</SCH02>
<!--Entity Identifier Code-->
<SCH03/>
<!--Name-->
<SCH04 xsi:nil="true"/>
<!--Date/Time Qualifier-->
<SCH05><!--Delivery Requested-->002</SCH05>
<!--Date-->
<SCH06>20180708</SCH06>
</SCH>
</SCHLoop1>
</PO1Loop1>
<PO1Loop1 type="Loop">
<PO1 type="Segment">
<!--Assigned Identification-->
<PO101 xsi:nil="true"/>
<!--Quantity Ordered-->
<PO102>500000</PO102>
<!--Unit or Basis for Measurement Code-->
<PO103><!--Each-->EA</PO103>
<!--Unit Price-->
<PO104>495</PO104>
<!--Basis of Unit Price Code-->
<PO105><!--Price per Thousand-->TP</PO105>
<!--Product/Service ID Qualifier-->
<PO106><!--Buyer's Part Number-->BP</PO106>
<!--Product/Service ID-->
<PO107>337S3748</PO107>
<!--Product/Service ID Qualifier-->
<PO108><!--Vendor's (Seller's) Part Number-->VP</PO108>
<!--Product/Service ID-->
<PO109>422244512</PO109>
</PO1>
<PIDLoop1 type="Loop">
<PID type="Segment">
<!--Item Description Type-->
<PID01>F</PID01>
<!--Product/Process Characteristic Code-->
<PID02/>
<!--Agency Qualifier Code-->
<PID03/>
<!--Product Description Code-->
<PID04 xsi:nil="true"/>
<!--Description-->
<PID05>HU-021 black widgets</PID05>
<!--Surface/Layer/Position Code-->
<PID06/>
<!--Source Subqualifier-->
<PID07 xsi:nil="true"/>
<!--Yes/No Condition or Response Code-->
<PID08/>
<!--Language Code-->
<PID09>EN</PID09>
</PID>
</PIDLoop1>
<SCHLoop1 type="Loop">
<SCH type="Segment">
<!--Quantity-->
<SCH01>500000</SCH01>
<!--Unit or Basis for Measurement Code-->
<SCH02><!--Each-->EA</SCH02>
<!--Entity Identifier Code-->
<SCH03/>
<!--Name-->
<SCH04 xsi:nil="true"/>
<!--Date/Time Qualifier-->
<SCH05><!--Delivery Requested-->002</SCH05>
<!--Date-->
<SCH06>20180708</SCH06>
</SCH>
</SCHLoop1>
</PO1Loop1>
<PO1Loop1 type="Loop">
<PO1 type="Segment">
<!--Assigned Identification-->
<PO101 xsi:nil="true"/>
<!--Quantity Ordered-->
<PO102>1500</PO102>
<!--Unit or Basis for Measurement Code-->
<PO103><!--Each-->EA</PO103>
<!--Unit Price-->
<PO104>3000</PO104>
<!--Basis of Unit Price Code-->
<PO105><!--Price per Hundred-->HP</PO105>
<!--Product/Service ID Qualifier-->
<PO106><!--Buyer's Part Number-->BP</PO106>
<!--Product/Service ID-->
<PO107>337S3749</PO107>
<!--Product/Service ID Qualifier-->
<PO108><!--Vendor's (Seller's) Part Number-->VP</PO108>
<!--Product/Service ID-->
<PO109>422241023</PO109>
</PO1>
<PIDLoop1 type="Loop">
<PID type="Segment">
<!--Item Description Type-->
<PID01>F</PID01>
<!--Product/Process Characteristic Code-->
<PID02/>
<!--Agency Qualifier Code-->
<PID03/>
<!--Product Description Code-->
<PID04 xsi:nil="true"/>
<!--Description-->
<PID05>100-20J widgets</PID05>
<!--Surface/Layer/Position Code-->
<PID06/>
<!--Source Subqualifier-->
<PID07 xsi:nil="true"/>
<!--Yes/No Condition or Response Code-->
<PID08/>
<!--Language Code-->
<PID09>EN</PID09>
</PID>
</PIDLoop1>
<SCHLoop1 type="Loop">
<SCH type="Segment">
<!--Quantity-->
<SCH01>100</SCH01>
<!--Unit or Basis for Measurement Code-->
<SCH02><!--Each-->EA</SCH02>
<!--Entity Identifier Code-->
<SCH03/>
<!--Name-->
<SCH04 xsi:nil="true"/>
<!--Date/Time Qualifier-->
<SCH05><!--Delivery Requested-->002</SCH05>
<!--Date-->
<SCH06>20180708</SCH06>
</SCH>
</SCHLoop1>
</PO1Loop1>
<CTTLoop1 type="Loop">
<CTT type="Segment">
<!--Number of Line Items-->
<CTT01>6</CTT01>
<!--Hash Total-->
<CTT02>500100</CTT02>
</CTT>
</CTTLoop1>
</TX-00401-850>
</TransactionSet>
</FunctionalGroup>
</Interchange>
大家可以看下这个XML结构,其标签名称与原始EDI文件的Segment名称都是对应的,从BEG开始,到CTT Segment,不同的segment涵盖不同的业务数据,根据该XML的Xpath取相关的业务数据,难易程度比直接处理EDI文件低很多。
接下来说说,如何从该XML文件获取数据,生成一个自定义XML。先看Mapping 源代码,这段代码可在Script Port直接运行。
<!-- NOTE: Do not edit -->
<rsb:info title="Custom Script" desc="This script will be executed when a file is processed.">
<input name="PortId" desc="The id of this port." />
<input name="MessageId" desc="The message id." />
<input name="FilePath" desc="The path of the file being processed." />
<input name="FileName" desc="The name of the file being processed." />
<output name="Data" desc="The data that will be write to Receive folder." />
<output name="FileName" desc="The name of the output file in Receive folder." />
</rsb:info>
<rsb:set attr="input.uri" value="[FilePath]"/>
<rsb:set attr="input.xpath" value="/Interchange/FunctionalGroup/TransactionSet/TX-00401-850" />
<rsb:call op="xmlDOMSearch" in="input">
<rsb:set attr="po.po_no" value="[xpath('BEG/BEG03') | def]" />
<rsb:set attr="output.data">
<PURORDER>
<CustomerId>[xpath("REF\[REF01='8M'\]/REF02") | def]</CustomerId>
<ReferenceNumber>[xpath("REF\[REF01='CR'\]/REF02") | def]</ReferenceNumber>
<PONumber>[xpath("BEG/BEG03") | def]</PONumber>
<BillAddress>[xpath("N1Loop1\[N1/N101='BY'\]/N2/N201") | def]</BillAddress>
<BillLine1>[xpath("N1Loop1\[N1/N101='BY'\]/N3/N301") | def]</BillLine1>
<BillLine2>[xpath("N1Loop1\[N1/N101='BY'\]/N3/N302") | def]</BillLine2>
<BillCity>[xpath("N1Loop1\[N1/N101='BY'\]/N4/N401") | def]</BillCity>
<BillState>[xpath("N1Loop1\[N1/N101='BY'\]/N4/N402") | def]</BillState>
<BillZip >[xpath("N1Loop1\[N1/N101='BY'\]/N4/N403") | def]</BillZip >
<BillCountry>[xpath("N1Loop1\[N1/N101='BY'\]/N4/N404") | def]</BillCountry>
<ShipAddress>[xpath("N1Loop1\[N1/N101='ST'\]/N2/N201") | def]</ShipAddress>
<ShipLine1>[xpath("N1Loop1\[N1/N101='ST'\]/N3/N301") | def]</ShipLine1>
<ShipLine2>[xpath("N1Loop1\[N1/N101='ST'\]/N3/N302") | def]</ShipLine2>
<ShipCity>[xpath("N1Loop1\[N1/N101='ST'\]/N4/N401") | def]</ShipCity>
<ShipState>[xpath("N1Loop1\[N1/N101='ST'\]/N4/N402") | def]</ShipState>
<ShipZip>[xpath("N1Loop1\[N1/N101='ST'\]/N4/N403") | def]</ShipZip>
<ShipCountry>[xpath("N1Loop1\[N1/N101='ST'\]/N4/N404") | def]</ShipCountry>
<rsb:call op="xmlDOMSearch?xpath=PO1Loop1">
<PURORDERLINEITEMS>
<ItemQty>[xpath("PO1/PO102") | def]</ItemQty>
<ItemQtyUnit>[xpath("PO1/PO103") | def]</ItemQtyUnit>
<ItemPrice>[xpath("PO1/PO104") | def]</ItemPrice>
<ItemPriceUnit>[xpath("PO1/PO105") | def]</ItemPriceUnit>
<ItemVendorNo>[xpath("PO1/PO109") | def]</ItemVendorNo>
<ItemDesc>[xpath("PIDLoop1/PID/PID05") | def]</ItemDesc>
<DueDate>[xpath("DTM\[DTM01='002'\]/DTM02") | def]</DueDate>
</PURORDERLINEITEMS>
</rsb:call>
</PURORDER>
</rsb:set>
</rsb:call>
<rsb:set attr="output.filename" value="PO850#[po.po_no].xml"/>
<rsb:push item="output"/>
代码实现部分,唯一的亮点就是调用了XMLDomSearch这个ops,掌握了它的调用,又如掌握了全世界:-)
如何正确调用XMLDOMSearch,请看下图。
输出结果如下:
<PURORDER>
<CustomerId>0056</CustomerId>
<ReferenceNumber>1070335099</ReferenceNumber>
<PONumber>0476696888</PONumber>
<BillAddress>Wayne Tech</BillAddress>
<BillLine1>125 WayneHigh Road.</BillLine1>
<BillLine2></BillLine2>
<BillCity></BillCity>
<BillState></BillState>
<BillZip ></BillZip>
<BillCountry></BillCountry>
<ShipAddress>Wayne Tech Plant 1</ShipAddress>
<ShipLine1>100 Wayne Ave.</ShipLine1>
<ShipLine2></ShipLine2>
<ShipCity>Chapel Hill</ShipCity>
<ShipState>MX</ShipState>
<ShipZip>27514</ShipZip>
<ShipCountry>US</ShipCountry>
<PURORDERLINEITEMS>
<ItemQty>500000</ItemQty>
<ItemQtyUnit>EA</ItemQtyUnit>
<ItemPrice>495</ItemPrice>
<ItemPriceUnit>TP</ItemPriceUnit>
<ItemVendorNo>422242224</ItemVendorNo>
<ItemDesc>500,000 red widgets</ItemDesc>
<DueDate></DueDate>
</PURORDERLINEITEMS>
<PURORDERLINEITEMS>
<ItemQty>100</ItemQty>
<ItemQtyUnit>EA</ItemQtyUnit>
<ItemPrice>395</ItemPrice>
<ItemPriceUnit>HP</ItemPriceUnit>
<ItemVendorNo>422242226</ItemVendorNo>
<ItemDesc>100 blue widgets</ItemDesc>
<DueDate></DueDate>
</PURORDERLINEITEMS>
<PURORDERLINEITEMS>
<ItemQty>500</ItemQty>
<ItemQtyUnit>EA</ItemQtyUnit>
<ItemPrice>210</ItemPrice>
<ItemPriceUnit>TP</ItemPriceUnit>
<ItemVendorNo>422201210</ItemVendorNo>
<ItemDesc>AH-0310 red widgets</ItemDesc>
<DueDate></DueDate>
</PURORDERLINEITEMS>
<PURORDERLINEITEMS>
<ItemQty>150</ItemQty>
<ItemQtyUnit>EA</ItemQtyUnit>
<ItemPrice>350</ItemPrice>
<ItemPriceUnit>TP</ItemPriceUnit>
<ItemVendorNo>422241452</ItemVendorNo>
<ItemDesc>F-100 blue widgets</ItemDesc>
<DueDate></DueDate>
</PURORDERLINEITEMS>
<PURORDERLINEITEMS>
<ItemQty>500000</ItemQty>
<ItemQtyUnit>EA</ItemQtyUnit>
<ItemPrice>495</ItemPrice>
<ItemPriceUnit>TP</ItemPriceUnit>
<ItemVendorNo>422244512</ItemVendorNo>
<ItemDesc>HU-021 black widgets</ItemDesc>
<DueDate></DueDate>
</PURORDERLINEITEMS>
<PURORDERLINEITEMS>
<ItemQty>1500</ItemQty>
<ItemQtyUnit>EA</ItemQtyUnit>
<ItemPrice>3000</ItemPrice>
<ItemPriceUnit>HP</ItemPriceUnit>
<ItemVendorNo>422241023</ItemVendorNo>
<ItemDesc>100-20J widgets</ItemDesc>
<DueDate></DueDate>
</PURORDERLINEITEMS>
</PURORDER>