本文整理汇总了C#中System.Xml.XmlNode.SelectSingleNode方法的典型用法代码示例。如果您正苦于以下问题:C# XmlNode.SelectSingleNode方法的具体用法?C# XmlNode.SelectSingleNode怎么用?C# XmlNode.SelectSingleNode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。
在下文中一共展示了XmlNode.SelectSingleNode方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
//引入命名空间
using System;
using System.IO;
using System.Xml;
public class Sample
{
public static void Main()
{
XmlDocument doc = new XmlDocument();
doc.Load("newbooks.xml");
// Create an XmlNamespaceManager to resolve the default namespace.
XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);
nsmgr.AddNamespace("bk", "urn:newbooks-schema");
// Select the first book written by an author whose last name is Atwood.
XmlNode book;
XmlElement root = doc.DocumentElement;
book = root.SelectSingleNode("descendant::bk:book[bk:author/bk:last-name='Atwood']", nsmgr);
Console.WriteLine(book.OuterXml);
}
}
示例2: Main
//引入命名空间
using System;
using System.IO;
using System.Xml;
public class Sample {
public static void Main() {
XmlDocument doc = new XmlDocument();
doc.Load("booksort.xml");
XmlNode book;
XmlNode root = doc.DocumentElement;
book=root.SelectSingleNode("descendant::book[author/last-name='Austen']");
//Change the price on the book.
book.LastChild.InnerText="15.95";
Console.WriteLine("Display the modified XML document....");
doc.Save(Console.Out);
}
}
示例3: Main
//引入命名空间
using System;
using System.IO;
using System.Xml;
public class Sample
{
public static void Main()
{
XmlDocument doc = new XmlDocument();
doc.Load("booksort.xml");
//Create an XmlNamespaceManager for resolving namespaces.
XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);
nsmgr.AddNamespace("bk", "urn:samples");
//Select the book node with the matching attribute value.
XmlNode book;
XmlElement root = doc.DocumentElement;
book = root.SelectSingleNode("descendant::book[@bk:ISBN='1-861001-57-6']", nsmgr);
Console.WriteLine(book.OuterXml);
}
}