读书人

xml有关问题

发布时间: 2012-01-21 21:31:43 作者: rapoo

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();

读书人网 >asp.net

热点推荐