<?xml version="1.0" encoding="utf-8" ?> - <area Country="China"> - <province ID="1" provinceID="110000" province="北京市"> - <City CityID="110100" City="市辖区"> <Piecearea PieceareaID="110101" Piecearea="东城区" /> <Piecearea PieceareaID="110102" Piecearea="西城区" /> <Piecearea PieceareaID="110103" Piecearea="崇文区" /> <Piecearea PieceareaID="110104" Piecearea="宣武区" /> <Piecearea PieceareaID="110105" Piecearea="朝阳区" /> <Piecearea PieceareaID="110106" Piecearea="丰台区" /> <Piecearea PieceareaID="110107" Piecearea="石景山区" /> <Piecearea PieceareaID="110108" Piecearea="海淀区" /> <Piecearea PieceareaID="110109" Piecearea="门头沟区" /> <Piecearea PieceareaID="110111" Piecearea="房山区" /> <Piecearea PieceareaID="110112" Piecearea="通州区" /> <Piecearea PieceareaID="110113" Piecearea="顺义区" /> <Piecearea PieceareaID="110114" Piecearea="昌平区" /> <Piecearea PieceareaID="110115" Piecearea="大兴区" /> <Piecearea PieceareaID="110116" Piecearea="怀柔区" /> <Piecearea PieceareaID="110117" Piecearea="平谷区" /> </City> - <City CityID="110200" City="县"> <Piecearea PieceareaID="110228" Piecearea="密云县" /> <Piecearea PieceareaID="110229" Piecearea="延庆县" /> </City> </province> </area>
读取上面XMl,获取某一个区的值,代码如下
XmlNode node = xmlDoc.SelectSingleNode("area/province[@provinceID=" + provinceID + "]/City[@CityID=" + cityID + "]/Piecearea[@PieceareaID=" + pieceareaID + "]"); string value = ((XmlElement)node).GetAttributeNode("Piecearea").Value;
读取XML某一个节点 条件筛选,布布扣,bubuko.com
原文地址:http://www.cnblogs.com/liang-ling/p/3865241.html