locked
Linq to xml query RRS feed

  • Question

  • User640374800 posted

    How would i return a number of PayeePayPerWeek elements (with sub elements) where a PayeeType is a certain value (ie if equal to "example type1" or "example type2" i would return 2 instances of PayeePayPerWeek...

    I tried this but am only getting back the 2 PayeeType elements not their parent element.

    var nodes = paydetails.Descendants().Where(n => n.Name.LocalName == "PayeeType").Where(x => x.Value == "example type1" || x.Value == "example type2").ToList();
    <n1:PayDetails>
    			<n1:BasicPayPerWeek>100</n1:BasicPayPerWeek>
    		<n1:PayeePayPerWeek>
                <n1:PayeeType>example type1</n1:PayeeType>
                <n1:PayeeRate>1.9</n1:PayeeRate>
                <n1:PayeeRateStatus>example status1</n1:PayeeRateStatus>
            </n1:PayeePayPerWeek>
            <n1:PayeePayPerWeek>
                <n1:PayeeType>example type2</n1:PayeeType>
                <n1:PayeeRate>5</n1:PayeeRate>
                <n1:PayeeRateStatus>example status2/n1:PayeeRateStatus>
            </n1:PayeePayPerWeek>
            <n1:PayeePayPerWeek>
                <n1:PayeeType>example type3</n1:PayeeType>
                <n1:PayeeRate>4</n1:PayeeRate>
                <n1:PayeeRateStatus>example status3</n1:PayeeRateStatus>
            </n1:PayeePayPerWeek>			
    		</n1:PayDetails>

    Thursday, January 21, 2021 11:34 AM

All replies

  • User1535942433 posted

    Hi mark1961,

    I tried this but am only getting back the 2 PayeeType elements not their parent element.

    Accroding to your description and codes,I don't understand your requirment clearly.I have created a test that I have get below result:

    {<PayeeType>example type1</PayeeType>}
    {<PayeeType>example type2</PayeeType>}

    Do you need below this:

    {<PayeePayPerWeek>example type1</PayeeType>} 
    {<PayeePayPerWeek>example type2</PayeeType>}

    Could you post more details to us?It will help us to solve your problems.

    Best regards,

    Yijing Sun

    Friday, January 22, 2021 6:18 AM