c#读取带有命名空间的XML

XML文件内容

<?xml version="1.0" standalone="no"?>
<svg width="1709px" height="886px"  οnlοad="init(evt)"  viewBox="0 0 1800 900" xmlns="http://www.w3.org/2000/svg"  xmlns:xlink="http://www.w3.org/1999/xlink" preserveAspectRatio="xMidYMid">
   <rect width="1709px" height="886px" fill="GradientInactiveCaption" />
   <rect x="88" y="369" width="1200px" height="15px" stroke-width="1" stroke="Black" fill="url(#79)" />
   <rect id="REED.ShapeElement.TrapezoidR" x="491" y="283" width="80px" height="185px" stroke-width="1" stroke="Transparent" fill="Transparent" />
</svg>

以下是读取方法:

class Program
    {
        static void Main(string[] args)
        {
            try
            {

                XmlDocument xmlDoc = new XmlDocument(); 
                xmlDoc.Load("F:\\汽机本体2.svg");

                XmlNamespaceManager nsmgr = new XmlNamespaceManager(xmlDoc.NameTable);
                nsmgr.AddNamespace("ns", "http://www.w3.org/2000/svg");
                XmlNode xn = xmlDoc.SelectSingleNode("//ns:svg", nsmgr);
                XmlNodeList xnl = xn.ChildNodes;
                Console.WriteLine("读取成功");
                Console.ReadLine();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                Console.ReadLine();
                throw;
            }
            
        }
    }
posted on 2014-07-25 16:24  泰山脚下 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/godxiangyu/p/3868352.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值