I have the following document XML
, and I want to do a search / filter by name GivenName using Xpath
. How to do?
XML
<bloodonors>
<donor>
<Number>1</Number>
<Gender>male</Gender>
<GivenName>Estevan</GivenName>
<Surname>Rodrigues</Surname>
</donor>
<donor>
<Number>2</Number>
<Gender>female</Gender>
<GivenName>Lucy</GivenName>
<Surname>Silva</Surname>
</donor>
<donor>
<Number>3</Number>
<Gender>female</Gender>
<GivenName>Beatriz</GivenName>
<Surname>Santos</Surname>
</donor>
</bloodonors>
My code
XmlDocument doc = new XmlDocument();
doc.Load(@ "Dadores.xml");
XmlNode root = doc.DocumentElement; //seleciona elemento do documento
XmlNodeList listaDador = root.SelectNodes("/bloodonors/donor[GivenName[contains(.,'" + GivenName + "'0] or Surname[contains(.,'" + Surname + "'0]");