Wednesday 13 June 2012

check if node exists









using System;
using System.IO;
using System.Xml;

public class Sample
{
public static void Main()
{
XmlDocument doc = new XmlDocument();
doc.Load("booksort.xml");

//Select the book node with the matching attribute value.
XmlNode nodeToFind;
XmlElement root = doc.DocumentElement;

// Selects all the title elements that have an attribute named lang
nodeToFind = root.SelectSingleNode("//title[@lang]");

if( nodeToFind != null )
{
// It was found, manipulate it.
}
else
{
// It was not found.
}
}
}

No comments:

Post a Comment