从weblink返回值

时间:2015-10-07 08:18:56

标签: c# xml

我试图从这个XML中获取余额值;

<eveapi version="2"><currentTime>2015-10-07 07:11:13</currentTime>
<result>
 <rowset name="accounts" key="accountID" columns="accountID,accountKey,balance">
 <row accountID="68743742" accountKey="1000" balance="67964604.15"/> 
 </rowset>
 </result> 
  <cachedUntil>2015-10-07 07:26:13</cachedUntil>
 </eveapi>

这是我尝试过的;

public void LoadBox1()
{
    string URL = "https://api.eveonline.com/char/AccountBalance.xml.aspx?keyID=4602486&&vCODE=BHGVeXQkRLKLkIkZQHdeyUxmUz9EfUwbvGzoc2eO4ZR8kRMYxk8PbD4LMwLF7BvH";
    XElement elements = XElement.Load(URL);
    txtBALANCE.Text = new XElement("eveapi", (from c in elements.Elements("result") select new XElement("result", c.Element("balance"))).Take(1)).Value;
}

private void button1_Click(object sender, EventArgs e)
{
    LoadBox1();
}

我对此疯狂猜测......是因为我想要的值是行的属性吗?

已解决

这是我如何做到的:

        public void LoadBox1()
    {
        string URL = "https://api.eveonline.com/char/AccountBalance.xml.aspx?keyID=4602486&&vCODE=BHGVeXQkRLKLkIkZQHdeyUxmUz9EfUwbvGzoc2eO4ZR8kRMYxk8PbD4LMwLF7BvH";
        XmlDocument xdoc = new XmlDocument();
        xdoc.Load(URL);
        XmlNodeList ndlist = xdoc.SelectNodes("/eveapi/result/rowset/row");
        foreach (XmlNode xmlnode in ndlist)
        {
            if (xmlnode.Attributes["balance"] != null) ;
                txtBALANCE.Text = xmlnode.Attributes["balance"].InnerText;
        }
    }

1 个答案:

答案 0 :(得分:0)

试试这个:

 txtBALANCE.Text =elements.Element("eveapi").Element("result").Element("rowset").Element("row").Attribute("balance").Value;