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文件**********************************************************************************
- ﹤?xml version="1.0" encoding="utf-8" ?﹥
- ﹤v:Games xmlns:v="www-shop-game"﹥
- ﹤v:Game name="文明3" type="standard"﹥
- ﹤Price﹥100﹤/Price﹥
- ﹤/Game﹥ //C# 操作XML之读取Xml
- ﹤v:Game name="文明3" type="classic"﹥
- ﹤Price﹥500﹤/Price﹥
- ﹤/Game﹥
- ﹤v:Game name="帝国时代"﹥
- ﹤Price﹥200﹤/Price﹥
- ﹤/Game﹥
- ﹤/Games﹥
IOS