zoukankan      html  css  js  c++  java
  • xml读取多层节点 枫

    • XmlDocument xml = new XmlDocument();  
    • xml.Load("D:\\Xml\\sellgame.xml")        
    • XmlNamespaceManager nsmgr =   
    • new XmlNamespaceManager(new XmlDocument().NameTable);  
    •  //建立Xml命名空间管理器对象  
    • nsmgr.AddNamespace("v","www-shop-game");  
    • //增加命名空间  ,C# 操作XML之读取Xml
    • string price = xml.SelectSingleNode(  
    • "v:Games/v:Game[@name='文明3']/Price",nsmgr).InnerText;  
    • //取得相应的节点值 
    ******读取所有文明3的**********************************************************************************


    • XmlNamespaceManager nsmgr =   
    • new XmlNamespaceManager(  
    • new XmlDocument().NameTable);    
    •   //建立Xml命名空间管理器对象  
    • nsmgr.AddNamespace("v","www-shop-game");   
    •  //增加命名空间  ,C# 操作XML之读取Xml
    • XmlNodeList nodeList = xml.SelectNodes(  
    • "v:Games/v:Game[@name='文明3']/Price",nsmgr);     
    •  //取得相应的节点数组  
    ******对应的xml文件**********************************************************************************



    1. ﹤?xml version="1.0" encoding="utf-8" ?﹥  
    2. ﹤v:Games xmlns:v="www-shop-game"﹥  
    3.     ﹤v:Game name="文明3" type="standard"﹥  
    4.         ﹤Price﹥100﹤/Price﹥  
    5.     ﹤/Game﹥  //C# 操作XML之读取Xml
    6.     ﹤v:Game name="文明3" type="classic"﹥   
    7.         ﹤Price﹥500﹤/Price﹥  
    8.     ﹤/Game﹥  
    9.     ﹤v:Game name="帝国时代"﹥  
    10.         ﹤Price﹥200﹤/Price﹥  
    11.     ﹤/Game﹥  
    12. ﹤/Games﹥
  • 相关阅读:
    如何节省 1TB 图片带宽?解密极致图像压缩
    微信亿级用户异常检测框架的设计与实践
    一文带你深度解析腾讯云直播答题方案
    kafka数据迁移实践
    揭密微信跳一跳小游戏那些外挂
    从蓝光到4K,腾讯视频高码率下载背后的技术
    GridControl列自动匹配宽度
    access的逻辑类型
    NPOI Excel类
    Access sql语句创建表及字段类型
  • 原文地址:https://www.cnblogs.com/mrray/p/2315583.html
Copyright © 2011-2022 走看看