小编Joe*_*eez的帖子

C#Foreach XML节点

我正在尝试将XML文件中的所有节点添加到listView中,并且我做错了但是我不能在我的生活中找到它,即使在查看了大量示例之后.这是XML片段:

<queue>
<slots>
<slot>
<status>Downloading</status>
<filename>file1</filename>
<size>1 GB</size>
</slot>
<slot>
<status>Downloading</status>
<filename>file2</filename>
<size>2 GB</size>
</slot>
</slots>
</queue>
Run Code Online (Sandbox Code Playgroud)

这是代码:

        XDocument xDoc = XDocument.Load(xmlFilePath);

        List<Download> list = new List<Download>();

        foreach (var download in xDoc.Descendants("slots"))
        {
            string filename = download.Element("filename").Value;
            string size = download.Element("size").Value;
            string status = download.Element("status").Value;
            list.Add(new Download { Filename = filename, Size = size, Status = status });              
        }
Run Code Online (Sandbox Code Playgroud)

任何帮助一如既往地非常感谢.

编辑:澄清一下,我得到一个NullReferenceException

string filename = download.Element("filename").Value;
Run Code Online (Sandbox Code Playgroud)

我知道列表视图丢失了,我还没有那么做:)

.net c# xml

5
推荐指数
1
解决办法
6780
查看次数

WP7 - 使用Web客户端/ HttpWebRequest的检索XML HTTPS

我试图从服务器检索XML文档和本地存储它作为一个字符串.在桌面.Net我不需要,我只是做了:

        string xmlFilePath = "https://myip/";
        XDocument xDoc = XDocument.Load(xmlFilePath);
Run Code Online (Sandbox Code Playgroud)

但是在WP7上会返回:

Cannot open 'serveraddress'. The Uri parameter must be a relative path pointing to content inside the Silverlight application's XAP package. If you need to load content from an arbitrary Uri, please see the documentation on Loading XML content using WebClient/HttpWebRequest.
Run Code Online (Sandbox Code Playgroud)

所以,我开始使用Web客户端/ HttpWebRequest的例子,从这里,但现在它返回:

The remote server returned an error: NotFound.
Run Code Online (Sandbox Code Playgroud)

是因为XML是https路径吗?或者因为我的路径没有以.XML结尾?我怎么知道的?谢谢你的帮助.

这是代码:

    public partial class MainPage : PhoneApplicationPage
{
    WebClient client = new WebClient();
    string baseUri = "https://myip:myport/service";
    public …
Run Code Online (Sandbox Code Playgroud)

.net c# xml windows-phone-7

4
推荐指数
1
解决办法
3万
查看次数

C#相当于"My.Computer.Network.Ping"

问题说真的,VB.NET有一个C#答案My.Computer.Network.Ping吗?

干杯!

.net c#

3
推荐指数
1
解决办法
7020
查看次数

C#将字符串转换为int(带舍入)

将值为"76.10"的字符串转换为整数为76的最简单方法是什么?

我使用Convert.ToInt32和Decimal尝试了几种不同的方法,但我似乎无法正确使用它?

编辑:这是Jon帮助我的代码:

            decimal t = Math.Round(decimal.Parse(info.HDDStatus));
            int v = (int)t;
Run Code Online (Sandbox Code Playgroud)

.net c#

2
推荐指数
1
解决办法
4135
查看次数

标签 统计

.net ×4

c# ×4

xml ×2

windows-phone-7 ×1