用c#获取这个xml值

rob*_*ert 2 c# xml

我需要获取文字旁边的数字,在这种情况下,数字是1

<SD>
<POPULARITY URL="google.com/" TEXT="1"/>
<REACH RANK="1"/>
<RANK DELTA="+0"/>
</SD>
Run Code Online (Sandbox Code Playgroud)

我怎样才能得到c#中的数字

谢谢

sca*_*tag 5

除了上面的例子,你可以尝试使用linq到xml

见下文.

    var str = @"<ALEXA VER='0.9' URL='google.com/' HOME='0' AID='='>

<SD TITLE='A' FLAGS='DMOZ' HOST='google.com'> 
<TITLE TEXT='Google                             '/> 
<ADDR STREET='' CITY='' STATE='' ZIP='' COUNTRY='' />
<CREATED DATE='15-Sep-1997' DAY='15' MONTH='09' YEAR='1997'/>
<PHONE NUMBER='unlisted'/>
<OWNER NAME='unlisted'/>
<EMAIL ADDR='dns-admin@google.com'/>
<LANG LEX='en'/>
<LINKSIN NUM='704402'/>
<SPEED TEXT='1581' PCT='48'/>
<REVIEWS AVG='4.5' NUM='524'/>
<CHILD SRATING='0'/>
<ASSOCS>
<ASSOC ID='googlecom'/></ASSOCS>
</SD>

<KEYWORDS>
<KEYWORD VAL='Mountain View'/>
</KEYWORDS><DMOZ>
<SITE BASE='google.com/' TITLE='Google' DESC='Enables users to search the Web, Usenet, and images. Features include PageRank, caching and translation of results, and an option to find similar pages. The companys focus is developing search technology.'>
<CATS>
<CAT ID='Top/Computers/Internet/Searching/Search_Engines/Google' TITLE='Search Engines/Google' CID='374822'/>
<CAT ID='Top/Regional/North_America/United_States/California/Localities/M/Mountain_View/Business_and_Economy/Industrial/Computers_and_Internet' TITLE='Industrial/Computers and Internet' CID='625367'/>
<CAT ID='Top/World/Arabic/???????/?????_??????/????????/?????_?_??????/???????_?_??????/??????_???' TITLE='??????? ? ??????/?????? ???' CID='204954'/>
<CAT ID='Top/World/Français/Informatique/Internet/Recherche/Moteurs_de_recherche/Google' TITLE='Moteurs de recherche/Google' CID='247347'/>
</CATS>
</SITE>
</DMOZ>
<SD>
<POPULARITY URL='google.com/' TEXT='1'/>
<REACH RANK='1'/>
<RANK DELTA='+0'/>
</SD>
</ALEXA>";

    var item = XElement.Parse(str);

    var subSet = item.Elements("SD");

    var actualItem =  subSet.Where(x => x.Element("POPULARITY") != null).First();

    var value = actualItem.Element("POPULARITY").Attribute("TEXT").Value;
Run Code Online (Sandbox Code Playgroud)

希望这可以帮助