XmlDocument加载有Xmlns的xml文档,使用Xpath
2013-10-17 15:29
218 查看
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); } }
None
<?xml version='1.0'?> <bookstore xmlns="urn:newbooks-schema"> <book genre="novel" style="hardcover"> <title>The Handmaid's Tale</title> <author> <first-name>Margaret</first-name> <last-name>Atwood</last-name> </author> <price>19.95</price> </book> <book genre="novel" style="other"> <title>The Poisonwood Bible</title> <author> <first-name>Barbara</first-name> <last-name>Kingsolver</last-name> </author> <price>11.99</price> </book> </bookstore>
相关文章推荐
- kettle中Get Data from XML , Jason Input , 文本文件输入 使用示例
- cd代码段
- [互联网面试笔试汇总C/C++-14] 判断一棵二叉树是否是二叉搜索树-微策略
- 3.1 CMMI3级——11个PA简述
- S3C2440-中断
- 使用严苛模式打破Android4.0以上平台应用中UI主线程的“独断专行”
- OCP-1Z0-051-V9.02-67题
- 相机控制
- 课时练习2
- mysql多个TimeStamp设置(转)
- nginx安装
- 分布式数据库组件——Database Link
- 收藏一些规范化输入输出的PHP函数
- python doc 简要介绍
- ETL
- 矩形并积
- ubuntu下关闭独立显卡
- 再读概率论与数理统计-1
- 轻松关掉Win7资源管理器最近的搜索痕迹保护我们的隐私
- Android使用OrmLite数据库框架 之 使用表配置文件