获取Xml中Attributes的描述文字

前端之家收集整理的这篇文章主要介绍了获取Xml中Attributes的描述文字前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
<dalian dn="nay">
<city cityX="378.65" cityY="177.05" cityname="庄河市" centername="庄河市" fontColor="FFFFFF" pyName="" state1="1" state2="0" stateDetailed="多云转晴" tem1="18" tem2="27" temNow="18" windState="东北风4-5级" windDir="东风" windPower="2级" humidity="81%" time="02:00" url="101070207"/>
<city cityX="259.5" cityY="252.8" cityname="普兰店市" centername="普兰店市" fontColor="FFFFFF" pyName="" state1="1" state2="0" stateDetailed="多云转晴" tem1="18" tem2="27" temNow="17" windState="东北风4-5级" windDir="北风" windPower="0级" humidity="72%" time="02:00" url="101070204"/>
<city cityX="222.75" cityY="212.7" cityname="瓦房店市" centername="瓦房店市" fontColor="FFFFFF" pyName="" state1="1" state2="0" stateDetailed="多云转晴" tem1="18" tem2="27" temNow="17" windState="东北风4-5级" windDir="西北风" windPower="2级" humidity="60%" time="02:00" url="101070202"/>
<city cityX="197.1" cityY="398.7" cityname="大连市" centername="大连市" fontColor="FFFF00" pyName="" state1="1" state2="0" stateDetailed="多云转晴" tem1="20" tem2="27" temNow="20" windState="东北风4-5级" windDir="北风" windPower="2级" humidity="63%" time="02:00" url="101070201"/>
<city cityX="368.6" cityY="289.55" cityname="长海县" centername="长海县" fontColor="FFFFFF" pyName="" state1="1" state2="0" stateDetailed="多云转晴" tem1="20" tem2="26" temNow="22" windState="东北风4-5级" windDir="北风" windPower="3级" humidity="87%" time="02:00" url="101070206"/>
</dalian>



// 1.创建xml文档对象  
XmlDocument xmlDoc = new XmlDocument ();  

// 2.用文档对象读取本地XML文件  
xmlDoc.Load (Application.dataPath + "/myXml.xml");  


XmlNode root = xmlDoc.SelectSingleNode ("dalian");
XmlNodeList list = root.ChildNodes;
// 3.获取第3个节点(下标从0开始)即大连市
String text = list [3].Attributes.GetNamedItem ("cityname").InnerText;
原文链接:/xml/296004.html

猜你在找的XML相关文章