I have the following XML File:
<persons>
<person name="shawn">
<age>34</age>
<hair style="spikes">red</hair>
</person>
<person name="mike">
<age>36</age>
<hair style="bald">red</hair>
</person>
<person name="shawn">
<age>38</age>
<hair style="bald">red</hair>
</person>
</persons>
Using XPath in C#, is it possible to select the person element where the name is "Shawn", and the hair style = "bald"?
I tried using:
XElement.XPathSelectElement("//person[@name='shawn'] | //person/hair[@style='bald']
but that gives me a reference to the hair element, and not the person element.
Thanks in advance :)
Peter
If you want someone who is both called shawn and is bald (which your question title suggests), you want:
//person[@name='shawn' and hair/@style='bald']
If you want people who are either called shawn or are bald (which it looks like you may do from the attempt in your question), you want:
//person[@name='shawn' or hair/@style='bald']
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With