Reputation: 407
i have an XML like
<Validation>
<Presentation>
<Slide Tag = "Pippo">
<Shape Name = "Pluto"/>
</Slide>
<Shape Name = "Pluto"/>
</Presentation>
</Validation>
how can i improve this c# code snippet
String xPath = string.Format("/Validation/Presentation/Shape[@Name='{0}'][1]", "Pluto");
XmlNode node = doc.DocumentElement.SelectSingleNode(xPath);
to get only the shape node with attribute Name "Pluto" whose parent have the attribute Tag "Pippo"?
Upvotes: 1
Views: 482
Reputation: 26846
You can get this node using following Xpath string:
string xPath = string.Format("//*[@Tag='{0}']/Shape[@Name='{1}']", "Pippo","Pluto");
XmlNode node = doc.DocumentElement.SelectSingleNode(xPath);
Upvotes: 4