1
I have the following document XML
, and I intend 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]");
Related in English: Extracting an XML element from an XML file using Xpath
– Marconi
What have you tried ? What errors are appearing ?
– LP. Gonçalves
I tried using Selectnodes, but I’m not getting it, I’ve searched the web, and I can’t find anything, this is my last resort
– Blazin
@Blazin put the code in C# that tried!
– Marconi
p.s - I am not very good at programming, I started a short time, hence I need project help
– Blazin
@Marconi already put in question the code I tried to use
– Blazin
@Blazin at first is just like that, I’ll try to help you around here if there’s not a likely answer that put one! Welcome to Stack overflow, recommend reading on tour to understand a little more how things work around here.
– Marconi
@Blazin added an answer!
– Marconi
@Blazin If Marconi’s answer solves your problem, mark it as accepted/correct.
– LP. Gonçalves