0

I am trying to grab the specific value of an attribute in:

http://data.alexa.com/data?cli=10&dat=snbamz&url=bing.com

<SD>
<POPULARITY URL="bing.com/" TEXT="16" SOURCE="panel"/>
<REACH RANK="16"/>
<RANK DELTA="-7"/>
<COUNTRY CODE="US" NAME="United States" RANK="9"/>
</SD>
</ALEXA>

I want to grab the value of

I have the current Console Code for this:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string url = "http://data.alexa.com/data?cli=10&dat=snbamz&url=bing.com";
            XmlDocument xmldoc = new XmlDocument();
            xmldoc.Load(url);
            XmlNode root = xmldoc.SelectSingleNode("//@RANK");

            //XmlNamespaceManager xnm1 = new XmlNamespaceManager(xmldoc.NameTable);
            //XmlNodeList nList1 = xmldoc.SelectNodes("//@RANK", xnm1);

            Console.WriteLine(root.ToString());
            Console.ReadLine();


        }
    }
}

But when I run it, I receive the following message in return:

System.Xml.XmlAttribute

What am I doing wrong?

1 Answer 1

2

Try changing:

Console.WriteLine(root.ToString());

to:

Console.WriteLine(root.Value);

Hope that helps.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.