我正在尝试将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)
我知道列表视图丢失了,我还没有那么做:)
我试图从服务器检索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) 问题说真的,VB.NET有一个C#答案My.Computer.Network.Ping吗?
干杯!
将值为"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)