Click here to Skip to main content
15,908,675 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to get data from xml, get RANK of google at in
XML
<country code="US" name="United States" rank="1/>"
but i don't know how to get. anyone can help me?
http://data.alexa.com/data?cli=10&url=http://google.com
Posted
Updated 7-Jun-13 0:00am
v3

1 solution

Hello,

For example, we'll take this xml structure :
XML
<root>
    <level1 name="A">
        <level2 name="A1" />
        <level2 name="A2" />
    </level1>
    <level1 name="B">
        <level2 name="B1" />
        <level2 name="B2" />
    </level1>
    <level1 name="C" />
</root>


We'll do that in C#/LINQ :
C#
//Load xml
XDocument xdoc = XDocument.Load("data.xml");

//Run query
var lv1s = from lv1 in xdoc.Descendants("level1")
           select new { 
               Header = lv1.Attribute("name").Value,
               Children = lv1.Descendants("level2")
           };

//Loop through results
foreach (var lv1 in lv1s){
        result.AppendLine(lv1.Header);
        foreach(var lv2 in lv1.Children)
             result.AppendLine("     " + lv2.Attribute("name").Value);
}

I think you can inspirate yourself from this example ;)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900