如何使用嵌套for循环从深层xml结构中获取值

如何使用嵌套for循环从深层xml结构中获取值,xml,loops,for-loop,nested,xquery,Xml,Loops,For Loop,Nested,Xquery,我是XQuery新手,无法从深层xml结构中获取数据: 以下是XML数据: <?xml version="1.0" encoding="UTF-8" standalone="yes" ?> <!-- Eingangs-Message --> <!-- root element --> <syncBusinessPartner xmlns='http://crm.igepa.com' xmlns:xsd='http://www.w3.org/2001/XM

我是XQuery新手,无法从深层xml结构中获取数据:

以下是XML数据:

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!-- Eingangs-Message -->
<!-- root element -->
<syncBusinessPartner xmlns='http://crm.igepa.com' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>
    <in0 xsi:type='ns1:AddressBookMaster' xmlns:ns1='http://data.common.jde.igepa.com'>
        <ns1:AddressBookMaster xsi:type='ns1:AddressBookMaster'>
            <ns1:GLBankAccount xsi:type='xsd:string'/>
            <ns1:actionMessageControl xsi:type='xsd:string'/>
            <ns1:addTypeCode4Purch xsi:type='xsd:string'>N</ns1:addTypeCode4Purch>
            <ns1:addressByDate xsi:type='ns1:AddressByDate'>
                <ns1:AddressByDate xsi:type='ns1:AddressByDate'>
                    <ns1:addressLine1 xsi:type='xsd:string'>FirmZus1 Abnahmetest 3 ATU             </ns1:addressLine1>
                    <ns1:addressLine2 xsi:type='xsd:string'>FirmZus2 Abnahmetest 3 ATU             </ns1:addressLine2>
                    <ns1:addressLine3 xsi:type='xsd:string'/>
                    <ns1:addressLine4 xsi:type='xsd:string'>Einzingergasse 4                        </ns1:addressLine4>
                    <ns1:addressNumber xsi:type='xsd:string'>890193</ns1:addressNumber>
                    <ns1:bulkMailingCenter xsi:type='xsd:string'/>
                    <ns1:carrierRoute xsi:type='xsd:string'>S</ns1:carrierRoute>
                    <ns1:city xsi:type='xsd:string'>Wien                     </ns1:city>
                    <ns1:country xsi:type='xsd:string'>AT </ns1:country>
                    <ns1:countyAddress xsi:type='xsd:string'/>
                    <ns1:dateBeginningEffective xsi:type='xsd:string'>0</ns1:dateBeginningEffective>
                    <ns1:state xsi:type='xsd:string'/>
                    <ns1:zipCodePostal xsi:type='xsd:string'>1210        </ns1:zipCodePostal>
                </ns1:AddressByDate>
            </ns1:addressByDate>
            <ns1:costCenter xsi:type='xsd:string'>         202</ns1:costCenter>
            <ns1:creditMessage xsi:type='xsd:string'/>
            <ns1:crmPositions xsi:type='ns1:CRMPositions'>
                <ns1:CRMPositions xsi:type='ns1:CRMPositions'>
                    <ns1:addressNumber xsi:type='xsd:string'>890193</ns1:addressNumber>
                    <ns1:commissionCode1 xsi:type='xsd:string'>0</ns1:commissionCode1>
                    <ns1:commissionCode2 xsi:type='xsd:string'>42666</ns1:commissionCode2>
                    <ns1:costCenter xsi:type='xsd:string'>202         </ns1:costCenter>
                    <ns1:crmPositionen xsi:type='xsd:string'>S42666 - 202 - Team Karton Dortmund               </ns1:crmPositionen>
                    <ns1:everestEventPoint01 xsi:type='xsd:string'>1</ns1:everestEventPoint01>
                    <ns1:everestEventPoint02 xsi:type='xsd:string'>K</ns1:everestEventPoint02>
                    <ns1:everestEventPoint03 xsi:type='xsd:string'>C</ns1:everestEventPoint03>
                    <ns1:productCode xsi:type='xsd:string'/>
                    <ns1:userDefinedCode xsi:type='xsd:string'/>
                    <ns1:userDefinedCodes xsi:type='xsd:string'/>
                </ns1:CRMPositions>
            </ns1:crmPositions>
            <ns1:customerMaster xsi:type='ns1:CustomerMaster'>
                <ns1:ARClass xsi:type='xsd:string'/>
                <ns1:ARHoldInvoices xsi:type='xsd:string'>N</ns1:ARHoldInvoices>
                <ns1:TRWDate xsi:type='xsd:string'>0</ns1:TRWDate>
            </ns1:customerMaster>
            <ns1:dateBeginningEffective xsi:type='xsd:string'>0</ns1:dateBeginningEffective>
            <ns1:dateScheduledIn xsi:type='xsd:string'>0</ns1:dateScheduledIn>
            <ns1:kanijAlpha xsi:type='xsd:string'/>
            <ns1:languagePreference xsi:type='xsd:string'>G </ns1:languagePreference>
            <ns1:miscCode3 xsi:type='xsd:string'/>
            <ns1:nameAlpha xsi:type='xsd:string'>ft abnahmetest3_ATU                     </ns1:nameAlpha>
            <ns1:nameRemark xsi:type='xsd:string'/>
            <ns1:personCorporationCode xsi:type='xsd:string'/>
            <ns1:reportCodeAddressBook001 xsi:type='xsd:string'>20 </ns1:reportCodeAddressBook001>
            <ns1:reportCodeAddressBook002 xsi:type='xsd:string'/>
            <ns1:reportCodeAddressBook003 xsi:type='xsd:string'>Yep</ns1:reportCodeAddressBook003>
            <ns1:reportCodeAddressBook004 xsi:type='xsd:string'>BOO</ns1:reportCodeAddressBook004>
            <ns1:reportCodeAddressBook005 xsi:type='xsd:string'/>
            <ns1:reportCodeAddressBook006 xsi:type='xsd:string'/>
            <ns1:reportCodeAddressBook007 xsi:type='xsd:string'/>
            <ns1:reportCodeAddressBook008 xsi:type='xsd:string'>902</ns1:reportCodeAddressBook008>
            <ns1:reportCodeAddressBook009 xsi:type='xsd:string'/>
            <ns1:reportCodeAddressBook010 xsi:type='xsd:string'>N  </ns1:reportCodeAddressBook010>
            <ns1:reportCodeAddressBook011 xsi:type='xsd:string'/>
            <ns1:reportCodeAddressBook012 xsi:type='xsd:string'/>
            <ns1:reportCodeAddressBook013 xsi:type='xsd:string'/>
            <ns1:reportCodeAddressBook014 xsi:type='xsd:string'/>
            <ns1:reportCodeAddressBook015 xsi:type='xsd:string'/>
            <ns1:reportCodeAddressBook016 xsi:type='xsd:string'/>
            <ns1:reportCodeAddressBook017 xsi:type='xsd:string'/>
            <ns1:reportCodeAddressBook018 xsi:type='xsd:string'/>
            <ns1:reportCodeAddressBook019 xsi:type='xsd:string'/>
            <ns1:reportCodeAddressBook020 xsi:type='xsd:string'/>
            <ns1:reportCodeAddressBook021 xsi:type='xsd:string'/>
            <ns1:reportCodeAddressBook022 xsi:type='xsd:string'/>
            <ns1:reportCodeAddressBook023 xsi:type='xsd:string'>5  </ns1:reportCodeAddressBook023>
            <ns1:reportCodeAddressBook024 xsi:type='xsd:string'/>
            <ns1:reportCodeAddressBook025 xsi:type='xsd:string'/>
            <ns1:reportCodeAddressBook026 xsi:type='xsd:string'/>
            <ns1:reportCodeAddressBook027 xsi:type='xsd:string'>M2 </ns1:reportCodeAddressBook027>
            <ns1:reportCodeAddressBook028 xsi:type='xsd:string'>J  </ns1:reportCodeAddressBook028>
            <ns1:reportCodeAddressBook029 xsi:type='xsd:string'/>
            <ns1:reportCodeAddressBook030 xsi:type='xsd:string'>200</ns1:reportCodeAddressBook030>
            <ns1:subledgerInactiveCode xsi:type='xsd:string'/>
            <ns1:taxID xsi:type='xsd:string'>AT10203040          </ns1:taxID>
            <ns1:taxID2 xsi:type='xsd:string'/>
            <ns1:timeScheduledIn xsi:type='xsd:string'>0</ns1:timeScheduledIn>
            <ns1:whoIsWho xsi:type='ns1:whoIsWho'>
                <ns1:WhoIsWho xsi:type='ns1:WhoIsWho'>
                    <ns1:addressNumber xsi:type='xsd:string'>890193</ns1:addressNumber>
                    <ns1:categoryCodeWhosWho001 xsi:type='xsd:string'/>
                    <ns1:categoryCodeWhosWho002 xsi:type='xsd:string'/>
                    <ns1:categoryCodeWhosWho003 xsi:type='xsd:string'/>
                    <ns1:categoryCodeWhosWho004 xsi:type='xsd:string'/>
                    <ns1:categoryCodeWhosWho005 xsi:type='xsd:string'/>
                    <ns1:categoryCodeWhosWho006 xsi:type='xsd:string'/>
                    <ns1:categoryCodeWhosWho007 xsi:type='xsd:string'/>
                    <ns1:categoryCodeWhosWho008 xsi:type='xsd:string'/>
                    <ns1:categoryCodeWhosWho009 xsi:type='xsd:string'/>
                    <ns1:categoryCodeWhosWho010 xsi:type='xsd:string'/>
                    <ns1:contactPhoneNumbers xsi:type='ns1:ContactPhoneNumbers'>
                        <ns1:ContactPhoneNumbers xsi:type='ns1:ContactPhoneNumbers'>
                            <ns1:addressNumber xsi:type='xsd:string'>890193</ns1:addressNumber>
                            <ns1:lineNumberID xsi:type='xsd:string'>0</ns1:lineNumberID>
                            <ns1:phoneAreaCode xsi:type='xsd:string'>0043  </ns1:phoneAreaCode>
                            <ns1:phoneNumber xsi:type='xsd:string'>12030405010         </ns1:phoneNumber>
                            <ns1:phoneNumberType xsi:type='xsd:string'>FAX </ns1:phoneNumberType>
                            <ns1:sequenceNumber xsi:type='xsd:string'>2</ns1:sequenceNumber>
                            <ns1:contactPersonalID xsi:type='xsd:string'>0</ns1:contactPersonalID>
                            <ns1:userID xsi:type='xsd:string'>ALENCLUD  </ns1:userID>
                            <ns1:programID xsi:type='xsd:string'>EP01012   </ns1:programID>
                            <ns1:workStationID xsi:type='xsd:string'>S250AP50  </ns1:workStationID>
                            <ns1:dateUpdated xsi:type='xsd:string'>115056</ns1:dateUpdated>
                            <ns1:timeLastUpdated xsi:type='xsd:string'>114648</ns1:timeLastUpdated>
                        </ns1:ContactPhoneNumbers>
                        <ns1:ContactPhoneNumbers xsi:type='ns1:ContactPhoneNumbers'>
                            <ns1:addressNumber xsi:type='xsd:string'>890193</ns1:addressNumber>
                            <ns1:lineNumberID xsi:type='xsd:string'>0</ns1:lineNumberID>
                            <ns1:phoneAreaCode xsi:type='xsd:string'>0043  </ns1:phoneAreaCode>
                            <ns1:phoneNumber xsi:type='xsd:string'>120304050           </ns1:phoneNumber>
                            <ns1:phoneNumberType xsi:type='xsd:string'/>
                            <ns1:sequenceNumber xsi:type='xsd:string'>1</ns1:sequenceNumber>
                            <ns1:contactPersonalID xsi:type='xsd:string'>0</ns1:contactPersonalID>
                            <ns1:userID xsi:type='xsd:string'>ALENCLUD  </ns1:userID>
                            <ns1:programID xsi:type='xsd:string'>EP01012   </ns1:programID>
                            <ns1:workStationID xsi:type='xsd:string'>S250AP50  </ns1:workStationID>
                            <ns1:dateUpdated xsi:type='xsd:string'>115056</ns1:dateUpdated>
                            <ns1:timeLastUpdated xsi:type='xsd:string'>114648</ns1:timeLastUpdated>
                        </ns1:ContactPhoneNumbers>
                    </ns1:contactPhoneNumbers>
                    <ns1:contactTitle xsi:type='xsd:string'/>
                    <ns1:descritptionCompressed xsi:type='xsd:string'>FT ABNAHMETEST3_ATU                     </ns1:descritptionCompressed>                    
                    <ns1:electronicAddress xsi:type='ns1:electronicAddress'>
                        <ns1.ElectronicAddress xsi:type='ns1:ElectronicAddress'>
                            <ns1:addressNumber xsi:type='xsd:string'>890193</ns1:addressNumber>
                            <ns1:electronicAddressType xsi:type='xsd:string'>I</ns1:electronicAddressType>
                            <ns1:emailAddress xsi:type='xsd:string'>www.igepa-its.de</ns1:emailAddress>
                            <ns1:lineNumberID xsi:type='xsd:string'>0</ns1:lineNumberID>
                            <ns1:sequenceNumber xsi:type='xsd:string'>1</ns1:sequenceNumber>
                        </ns1.ElectronicAddress>
                    </ns1:electronicAddress>                    
                    <ns1:kanijalpha xsi:type='xsd:string'/>
                    <ns1:lineNumberID xsi:type='xsd:string'>0</ns1:lineNumberID>
                    <ns1:nameAlpha xsi:type='xsd:string'>ft abnahmetest3_ATU                     </ns1:nameAlpha>
                    <ns1:nameGiven xsi:type='xsd:string'/>
                    <ns1:nameMailing xsi:type='xsd:string'>Firma Abnahmetest 3 ATU                 </ns1:nameMailing>
                    <ns1:nameMiddle xsi:type='xsd:string'/>
                    <ns1:nameSurname xsi:type='xsd:string'/>
                    <ns1:remark1 xsi:type='xsd:string'/>
                    <ns1:salutationName xsi:type='xsd:string'/>
                    <ns1:secondMailingName xsi:type='xsd:string'/>
                    <ns1:sequenceNumber xsi:type='xsd:string'>0.00</ns1:sequenceNumber>
                    <ns1:typeCode xsi:type='xsd:string'/>
                    <ns1:userID xsi:type='xsd:string'>ALENCLUD  </ns1:userID>
                    <ns1:programID xsi:type='xsd:string'>EP01012   </ns1:programID>
                    <ns1:workStationID xsi:type='xsd:string'>S250AP50  </ns1:workStationID>
                    <ns1:dateUpdated xsi:type='xsd:string'>115056</ns1:dateUpdated>
                    <ns1:timeLastUpdated xsi:type='xsd:string'>114648</ns1:timeLastUpdated>
                    <ns1:contactType xsi:type='xsd:string'/>
                    <ns1:nickName xsi:type='xsd:string'/>
                    <ns1:gender xsi:type='xsd:string'/>
                    <ns1:dateOfBirth xsi:type='xsd:string'>0</ns1:dateOfBirth>
                    <ns1:monthOfBirth xsi:type='xsd:string'>0</ns1:monthOfBirth>
                    <ns1:yearOfBirth xsi:type='xsd:string'>0</ns1:yearOfBirth>
                    <ns1:categoryCode01 xsi:type='xsd:string'/>
                    <ns1:categoryCode02 xsi:type='xsd:string'/>
                    <ns1:categoryCode03 xsi:type='xsd:string'/>
                    <ns1:categoryCode04 xsi:type='xsd:string'/>
                    <ns1:categoryCode05 xsi:type='xsd:string'/>
                    <ns1:categoryCode06 xsi:type='xsd:string'/>
                    <ns1:categoryCode07 xsi:type='xsd:string'/>
                    <ns1:categoryCode08 xsi:type='xsd:string'/>
                    <ns1:categoryCode09 xsi:type='xsd:string'/>
                    <ns1:categoryCode10 xsi:type='xsd:string'/>
                    <ns1:functionCode xsi:type='xsd:string'/>
                    <ns1:preferedContactMethod xsi:type='xsd:string'/>
                    <ns1:primaryContact xsi:type='xsd:string'>0  </ns1:primaryContact>
                    <ns1:futureUseIndicator xsi:type='xsd:string'/>
                    <ns1:uniqueIdentifier xsi:type='xsd:string'/>
                    <ns1:synchronizationStatus xsi:type='xsd:string'>0</ns1:synchronizationStatus>
                    <ns1:serverStatus xsi:type='xsd:string'>0</ns1:serverStatus>
                </ns1:WhoIsWho>
            </ns1:whoIsWho>
        </ns1:AddressBookMaster>
    </in0>
    <in1>
        <string xsi:type='xsd:string'>crm_ig</string>
    </in1>
</syncBusinessPartner>

N
FirmZus1 Abnahmetest 3 ATU
FirmZus2 Abnahmetest 3 ATU
Einzingergasse 4
890193
s
维也纳
在
0
1210
202
890193
0
42666
202
S42666-202-卡尔顿多特蒙德队
1.
K
C
N
0
0
0
G
英国航空公司
20
是的
喝倒采
902
N
5.
平方米
J
200
电话10203040
0
890193
890193
0
0043
12030405010
传真
2.
0
阿伦clud
EP01012
S250AP50
115056
114648
890193
0
0043
120304050
1.
0
阿伦clud
EP01012
S250AP50
115056
114648
英国航空公司
890193
我
www.igepa-its.de
0
1.
0
英国航空公司
Firma Abnahmetest 3 ATU
0
阿伦clud
EP01012
S250AP50
115056
114648
0
0
0
0
0
0
客户关系管理
我想从lineNumberID为“0”且electronicAddressType为“I”的electronicAddress元素获取电子邮件地址

在我看来,我必须通过electronicAddress循环遍历WhoIsWho中的每个WhoIsWho元素和WhoIsWho内部的每个WhoIsWho元素,我期望得到以下结果

<ige:HomePage>www.webaddress.de</ige:HomePage>
www.webaddress.de
我的XQuery:

xquery version "1.0" encoding "utf-8";
(:: OracleAnnotationVersion "1.0" ::)
declare namespace ns1="http://crm.igepa.com";
(:: import schema at "../ProxyService/WSDL/IGEPA_PS_WSDL_BUSINESSPARTNER_E1_9_0_V1R0.wsdl" ::)
declare namespace ns2="http://siebel.com/CustomUI";
(:: import schema at "../BusinessService/WSDL/IGEPA_BS_WSDL_BUSINESSPARTNER_E1_9_0_V1R0.wsdl" ::)
declare namespace ige = "http://www.siebel.com/xml/IGEPA%20Firmen%20WS%20Inbound%20IO";
declare namespace dat = "http://data.common.jde.igepa.com";
declare namespace functx = "http://www.functx.com";
declare variable $mapBusinessPartner as element() (:: schema-element(ns1:syncBusinessPartner) ::) external;

declare function local:func($mapBusinessPartner as element() (:: schema-element(ns1:syncBusinessPartner) ::)) as element() (:: schema-element(ns2:IGEPAFirmenWSInboundSyncBusinessPartnerToCRM_1_Input) ::) {
    <ns2:IGEPAFirmenWSInboundSyncBusinessPartnerToCRM_1_Input>
        <ige:ListOfIgepaFirmenWsInboundIo>{
            for $AddressBookMaster in $mapBusinessPartner/ns1:in0/dat:AddressBookMaster
                return <ige:Account>              
                    <ige:HomePage>{
                        data($AddressBookMaster/dat:whoIsWho/dat:WhoIsWho/dat:electronicAddress/dat:ElectronicAddress[dat:lineNumberID = "0" and dat:electronicAddressType = "I"]/dat:emailAddress)
                    }
                    </ige:HomePage>                                                       
                </ige:Account>
        }
        </ige:ListOfIgepaFirmenWsInboundIo></ns2:IGEPAFirmenWSInboundSyncBusinessPartnerToCRM_1_Input>
};
local:func($mapBusinessPartner)
xquery版本“1.0”编码“utf-8”;
(::OracleAnnotationVersion“1.0”:)
声明命名空间ns1=”http://crm.igepa.com";
(::在“./ProxyService/WSDL/IGEPA_PS_WSDL_BUSINESSPARTNER_E1_9_0_V1R0.WSDL”导入架构):)
声明命名空间ns2=”http://siebel.com/CustomUI";
(::在“./BusinessService/WSDL/IGEPA_BS_WSDL_BUSINESSPARTNER_E1_9_0_V1R0.WSDL”导入架构):)
声明命名空间ige=”http://www.siebel.com/xml/IGEPA%20Firmen%20WS%20Inbound%20IO";
声明命名空间dat=”http://data.common.jde.igepa.com";
声明命名空间functx=”http://www.functx.com";
将变量$mapBusinessPartner声明为元素()(::架构元素(ns1:syncBusinessPartner)::)外部;
将函数local:func($mapBusinessPartner作为元素()(::架构元素(ns1:syncBusinessPartner)::)声明为元素()(::架构元素(ns2:IGEPAffirmenWSInboundSyncBusinessPartnerToCrm_1_输入):){
{
对于$MAP中的$AddressBookMaster业务伙伴/ns1:in0/dat:AddressBookMaster
回来
{
数据($AddressBookMaster/d)
declare namespace dat = "http://data.company.com";

<ige:HomePage>{
  /element/in0/dat:AddressBook/dat:whoIsWho/dat:WhoIsWho/dat:electronicAddress/dat:ElectronicAddress[dat:lineNumberID = 0 and dat:electronicAddressType = "I"]/dat:emailAddress/data()
}</ige:HomePage>