日期:2014-05-20  浏览次数:20512 次

xml问题,在线等。。。
xml文件格式如下
<?xml   version= "1.0 "   encoding= "utf-8 "   ?>
<Vocation>
<VocationTypeFather   Value= "1000 "   Text= "请选择行业类别 ">
<VocationTypeSon   Value= "2000 "   Text= "请选择职位类别 "> </VocationTypeSon>
</VocationTypeFather>
<VocationTypeFather   Value= "1001 "   Text= "计算机硬件 ">
<VocationTypeSon   Value= "2001 "   Text= "网络工程师 ">
<VocationTypeGrandson   Value= "3001 "   Text= "布线原理 "> </VocationTypeGrandson>
</VocationTypeSon>
</VocationTypeFather>
</Vocation>

请问,如果我知道了某个节点的Value属性,怎么样取得该节点的Text属性,请给出代码,谢谢

------解决方案--------------------
using System.Xml;

////////////////////////////////////


string strText= " ";
XmlTextReader xr = new XmlTextReader(Server.MapPath(null)+ "\\test.xml ");
xr.MoveToAttribute( "Vocation ");
while(xr.Read())
{
if(xr.Name.Equals( "VocationTypeFather "))
{
if (xr.GetAttribute( "Value ")== "1000 ")
{
strText = xr.GetAttribute( "Text ");
break;
}
}
}
xr.Close();