码迷,mamicode.com
首页 > 其他好文 > 详细

读取XML某一个节点 条件筛选

时间:2014-07-24 12:09:55      阅读:137      评论:0      收藏:0      [点我收藏+]

标签:blog   io   re   c   代码   div   ar   har   

 <?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

读取XML某一个节点 条件筛选

标签:blog   io   re   c   代码   div   ar   har   

原文地址:http://www.cnblogs.com/liang-ling/p/3865241.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!