a question about xpath expression

G

Guest

Hi there,

I've got an XML document and I would like to remove any elements that have
certain value, say "TagNotRequired". I tried the following code but it didn't
work. The count of nodes is always 0 instead of the number of nodes with
TagNotRequired value inside. Please help! Thanks!

XmlNode rootNode = doc.DocumentElement;
XmlNodeList nodes = rootNode.SelectNodes("*[*='TagNotRequired']");
foreach(XmlNode node in nodes)
{
rootNode.RemoveChild(node);
}


Cloud
 
G

Guest

Hi,

I figured out how to do it:

The xpath should be "//*/*[*='NodeToBeRemoved']".

Thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top