[英]Retrieve XML WP7
I am wondering why when I retrive my XML i can't get any items from it . 我想知道为什么当我检索我的XML时,我无法从中获取任何项目。
So basically I use the phone to connect to my web service. 所以基本上我用手机连接到我的网络服务。
The XML returns a TUPLE of directory info and file info . XML返回目录信息和文件信息的TUPLE。
<TupleOfArrayOfDirectoryInfoArrayOfFileInfoe_PmhuPqo xmlns="http://schemas.datacontract.org/2004/07/System" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<m_Item1 xmlns:a="http://schemas.datacontract.org/2004/07/System.IO">
<a:DirectoryInfo>
<OriginalPath xmlns="" xmlns:b="http://www.w3.org/2001/XMLSchema" i:type="b:string">AETN</OriginalPath>
<FullPath xmlns="" xmlns:b="http://www.w3.org/2001/XMLSchema" i:type="b:string">C:\inetpub\wwwroot\Files\TEST1</FullPath>
</a:DirectoryInfo>
<a:DirectoryInfo>
<OriginalPath xmlns="" xmlns:b="http://www.w3.org/2001/XMLSchema" i:type="b:string">BT</OriginalPath>
<FullPath xmlns="" xmlns:b="http://www.w3.org/2001/XMLSchema" i:type="b:string">C:\inetpub\wwwroot\Files\TEST2</FullPath>
</a:DirectoryInfo>
<a:DirectoryInfo>
<OriginalPath xmlns="" xmlns:b="http://www.w3.org/2001/XMLSchema" i:type="b:string">Comixology</OriginalPath>
<FullPath xmlns="" xmlns:b="http://www.w3.org/2001/XMLSchema" i:type="b:string">C:\inetpub\wwwroot\Files\TEST3</FullPath>
</a:DirectoryInfo>
On my code on windows phone 7 application,I am using this piece of code after I download the xml from the right url : 在我的Windows Phone 7应用程序代码上,我从右侧URL下载xml后使用这段代码:
void wc_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
if (e.Error == null)
{
XDocument xdoc = XDocument.Parse(e.Result, LoadOptions.None);
var folders = from query in xdoc.Descendants("DirectoryInfo")
select new Folder
{
Name = (string)query.Element("OriginalPath"),
};
listBox2.ItemsSource = folders;
}
}
I get this error : 我收到此错误:
'System.Collections.IEnumerable' does not contain a definition for 'System' and no extension method 'System' accepting a first argument of type 'System.Collections.IEnumerable' could be found (are you missing a using directive or an assembly reference?)
Don't know about the error, but the problem with no elements returned is because you have a namespace applied on the DirectoryInfo
elements, so you have to search using it: 不知道错误,但没有返回元素的问题是因为您在
DirectoryInfo
元素上应用了命名空间,因此您必须使用它进行搜索:
void wc_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
if (e.Error == null)
{
XDocument xdoc = XDocument.Parse(e.Result, LoadOptions.None);
XNamespace aNamespace = XNamespace.Get("http://schemas.datacontract.org/2004/07/System.IO");
var folders = from query in xdoc.Descendants(aNamespace.GetName("DirectoryInfo"))
select new Folder
{
Name = (string)query.Element("OriginalPath"),
};
listBox2.ItemsSource = folders;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.