日期:2014-05-19  浏览次数:20526 次

如何用asp.net读取xml文件中的某个值?
我有下面这个myalexa.xml文件,请问如何用asp.net读取下面文件中的 <POPULARITY   URL= "xxxx.net/ "   TEXT= "5980955 "/> 这行,并显示出来?谢谢大家(我是用c#的)我搞来搞去都总是出错,因为myalexa.xml文件 <POPULARITY   URL= "xxxx.net/ "   TEXT= "5980955 "/> 这行,不一定每次都会有,有时有,有时没有,请大家帮忙看看如何写才会判断,如果存在就显示为:存在:xxxx.net   值是:5980955   不存在就显示为:存在:xxxx.net   值是:0  
谢谢大家  
===================

<?xml   version= "1.0 "   encoding= "UTF-8 "?>

<ALEXA   VER= "0.9 "   URL= "xxxx.net/ "   HOME= "0 "   AID= "= ">
<RLS   TITLE= "Related   Links "   PREFIX= "http:// "   more   = "0 ">
<RL   HREF= "www.icq.com/download "   TYPE= "link "   SRC= "Siblinks "   TITLE= "Download   Icq   -   Icq.com "   CONF= "000 "   ASIN= "B00006ENEO "/>
</RLS>
<SD   TITLE= "Alexa   Site   Data "   FLAGS= " ">
<ADDR   STREET= "33   rue   de   la   Gare "   CITY= "DEUIL-LA-BARRE,   95170 "   STATE= " "   ZIP= " "   COUNTRY= "Fr "/>
<CREATED   DATE= "21-Feb-2000 "   DAY= "21 "   MONTH= "02 "   YEAR= "2000 "/>
<OWNER   NAME= "sexfrance "/>
<EMAIL   ADDR= "support@moniker.com "/>
<LANG   LEX= "en "   CODE= "us-ascii "/>
<LINKSIN   NUM= "44 "/>
<POPULARITY   URL= "xxxx.net/ "   TEXT= "5980955 "/>
<RANK   DELTA= "+1196769 "/>
<CHILD   SRATING= "31 "/>
<REACH   RANK= "4220387 "/>
</SD>

</ALEXA>

------解决方案--------------------
XmlDocument xd = new XmlDocument();
xd.LoadXml(..);
XmlNode xd = rssDoc.SelectSingleNode( "ALEXA/POPULARITY ");
if (xd != null)
Response.Write( "存在: " + xdrss.Attributes[ "URL "].Value + "值是: " + xdrss.Attributes[ "TEXT "].Valuexe;
else
Response.Write( "不存在:xxxx.net 值是:0 ");