从webblink返回值

本文关键字:返回值 webblink | 更新日期: 2023-09-27 18:16:27

我试图从这个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();
}

我胡乱猜了一下…是因为我想要的值是row的一个属性吗?

解决

我是这样做的:

        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;
        }
    }

从webblink返回值

试试这个:

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