0

I am trying to select a file with Xpath . If the Xpath finds a matching value in:

(//Party/PartyIdentification/ID[text()="6655779999"]) OR (//Party/PartyTaxScheme/CompanyID[text()="US6655779999"] AND TaxScheme/ID = DEY) OR (//Party/PartyTaxScheme/CompanyID[text()="US6655779999"] AND TaxScheme/ID = BSY)

it selects the right file.

I started off using: //BuyerParty/Party/PartyIdentification/ID[text()="6655779999"] and it works perfect!

But I can't figure out how to extend the xpath to also check the other two paths with their DEY and BSY conditions. I spend weeks so far and turned the forum inside out to find an answer, but with no luck.

The reson for this OR condition is that one, two or all three of the elements might exist in the xml file. I never know which one prior. I need to get at least one match of the three matching criteria above to be sure to select the right file.

Any ideas on how to solve this?

<ROOT>
<BuyerParty>
    <Party>
        <PartyIdentification>
            <ID>6655779999</ID>
        </PartyIdentification>
        <PartyName>
            <Name>Charly</Name>
        </PartyName>
        <Address>
            <StreetName>El Cajon Boulevard</StreetName>
            <CityName>San Diego</CityName>
            <PostalZone>92104</PostalZone>
            <Country>
                <IdentificationCode>US</IdentificationCode>
            </Country>
        </Address>
        <PartyTaxScheme>
            <CompanyID>US11432112341</CompanyID>
            <TaxScheme>
                <ID>DEY</ID>
            </TaxScheme>
        </PartyTaxScheme>
        <PartyTaxScheme>
            <CompanyID>US1143211234</CompanyID>
            <TaxScheme>
                <ID>BSY</ID>
            </TaxScheme>
        </PartyTaxScheme>
        <Contact>
            <Telephone>555-5555555</Telephone>
        </Contact>
    </Party>
</BuyerParty>

1 Answer 1

2

you can use the | (or) selector

//Party/PartyIdentification/ID[text()="6655779999"]|//Party/PartyTaxScheme/CompanyID[following-sibling::TaxScheme/ID = 'DEY' or following-sibling::TaxScheme/ID = 'BSY'][text()="US11432112341"]
Sign up to request clarification or add additional context in comments.

1 Comment

Looks very promising! But what if CompanyID have different matching criteria for TaxScheme/ID = 'DEY' and TaxScheme/ID = 'BSY'? Let's say US11432112341 for DEY and US123 for BSY

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.