Home > Software design >  WPF XmlNodeList how to SelectNodes with multiple same element nodes and attributes?
WPF XmlNodeList how to SelectNodes with multiple same element nodes and attributes?

Time:11-16

I need to make 2 xPath(s) where it displays the Procedure's description:

  • IF EVERY Step finished is equal to "True"
  • If only one of Step finished is true.

XML File:

<Procedures>
    <Procedure>
        <description>Work1</description>
        <Steps>
            <Step finished="False" no="1">Step1</etape>
            <Step finished="False" no="2">Step2</etape>
            <Step finished="False" no="4">Step3</etape>
            <Step finished="True" no="5">Step4</etape>
            
        </Steps>
    </Procedure>
    </Procedures>

What I've tried:

  • Expected to see the procedure's description if every step finished is equal to True but it does not work. XmlNodeList testList = doc.SelectNodes("//Procedure/description[//Step/@finished='True']");

CodePudding user response:

These are the two approaches:

  1. EVERY Step finished is equal to "True"

    /Procedures/Procedure/Steps[count(Step)=count(Step[@finished='True'])]/../description
    
  2. ONLY one of Step finished is "True"

    /Procedures/Procedure/Steps[Step/@finished='True']/../description
    

Of course /Procedures/Procedure... can be replaced by //Procedure....

CodePudding user response:

At least on Step with finished being True: //Procedure[Steps/Step/@finished = 'True']/description.

No Step with finished being False: //Procedure[not(Steps/Step/@finished = 'False')]/description.

  • Related