Windows Phone 7:将网站 XML 解析为 XDocument
我在 WP7 上尝试从网站解析 XML 时似乎遇到问题。由于某种原因,它永远不会填充呼叫。没有错误,xml 看起来不错,我指定了 NS,但仍然没有任何结果。
我在这里错过了一些非常简单的东西吗? 4个小时过去了,我的头撞在桌子上。
我的 C# 技能已经有 2 个月了,所以可能是我(可能会是)。
这是我用来解析从网站接收到的 XML 的代码...
public void ParseCallSignData(object sender, DownloadStringCompletedEventArgs e)
{
if (e.Error == null)
{
string s = e.Result;
XDocument doc;
XmlReaderSettings settings = new XmlReaderSettings();
settings.DtdProcessing = DtdProcessing.Ignore;
using (XmlReader reader = XmlReader.Create(new StringReader(s), settings))
{
doc = XDocument.Load(reader);
}
XNamespace ns = @"http://www.qrz.com";
var calldata = from query in doc.Descendants(ns + "Callsign")
select new callsign
{
call = (string)query.Element(ns +"call")
};
这就是我正在尝试解析的 XML。
<?xml version="1.0" encoding="iso-8859-1" ?>
- <QRZDatabase version="1.18" xmlns="http://www.qrz.com">
- <Callsign>
<call>W7EIX</call>
<dxcc>223</dxcc>
<fname>DICK</fname>
<name>TONITON</name>
<country>United States</country>
<lat>25.586910</lat>
<lon>-95.039318</lon>
<grid>EL29lo</grid>
<county>Harris</county>
<ccode>271</ccode>
<land>England</land>
<class>A</class>
<codes>ETP</codes>
<qslmgr>DIRECT PREFERRED NO SAE REQUIRED!</qslmgr>
<u_views>1716</u_views>
<moddate>2010-07-05 19:32:12</moddate>
<MSA>3360</MSA>
<AreaCode>713</AreaCode>
<TimeZone>Central</TimeZone>
<GMTOffset>-6</GMTOffset>
<DST>Y</DST>
<eqsl>1</eqsl>
<mqsl>1</mqsl>
<cqzone>0</cqzone>
<ituzone>0</ituzone>
<locref>3</locref>
<born>1968</born>
<lotw>1</lotw>
</Callsign>
- <Session>
<Key>afff7a6dfdff36f68fffb7dfff49fc7</Key>
<Count>18</Count>
<SubExp>Mon Sep 19 07:00:00 2011</SubExp>
<GMTime>Wed Aug 3 21:06:58 2011</GMTime>
<Remark>cpu: 0.073s</Remark>
</Session>
</QRZDatabase>
I seem to be having an issue on WP7 trying to Parse XML from a website. For some reason it never populates call. No errors, the xml looks good, I am specifying the NS, but still nothing.
Am I missing something really simple here? 4 hours in and I am banging my head on the desk.
My C# skills are 2 months old, so it could be me (probably will be).
This is my code that I am using to Parse the received XML from a website...
public void ParseCallSignData(object sender, DownloadStringCompletedEventArgs e)
{
if (e.Error == null)
{
string s = e.Result;
XDocument doc;
XmlReaderSettings settings = new XmlReaderSettings();
settings.DtdProcessing = DtdProcessing.Ignore;
using (XmlReader reader = XmlReader.Create(new StringReader(s), settings))
{
doc = XDocument.Load(reader);
}
XNamespace ns = @"http://www.qrz.com";
var calldata = from query in doc.Descendants(ns + "Callsign")
select new callsign
{
call = (string)query.Element(ns +"call")
};
And this is the XML I am trying to parse.
<?xml version="1.0" encoding="iso-8859-1" ?>
- <QRZDatabase version="1.18" xmlns="http://www.qrz.com">
- <Callsign>
<call>W7EIX</call>
<dxcc>223</dxcc>
<fname>DICK</fname>
<name>TONITON</name>
<country>United States</country>
<lat>25.586910</lat>
<lon>-95.039318</lon>
<grid>EL29lo</grid>
<county>Harris</county>
<ccode>271</ccode>
<land>England</land>
<class>A</class>
<codes>ETP</codes>
<qslmgr>DIRECT PREFERRED NO SAE REQUIRED!</qslmgr>
<u_views>1716</u_views>
<moddate>2010-07-05 19:32:12</moddate>
<MSA>3360</MSA>
<AreaCode>713</AreaCode>
<TimeZone>Central</TimeZone>
<GMTOffset>-6</GMTOffset>
<DST>Y</DST>
<eqsl>1</eqsl>
<mqsl>1</mqsl>
<cqzone>0</cqzone>
<ituzone>0</ituzone>
<locref>3</locref>
<born>1968</born>
<lotw>1</lotw>
</Callsign>
- <Session>
<Key>afff7a6dfdff36f68fffb7dfff49fc7</Key>
<Count>18</Count>
<SubExp>Mon Sep 19 07:00:00 2011</SubExp>
<GMTime>Wed Aug 3 21:06:58 2011</GMTime>
<Remark>cpu: 0.073s</Remark>
</Session>
</QRZDatabase>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
那些“
-
”字符看起来很可疑。他们不应该在那里。 (...尽管这可能是浏览器剪切粘贴的产物)Those '
-
' characters look suspect. They shouldn't be there. (...although this might be an artefact of cut'n'paste from the browser)3个月后,但对于那些想知道的人来说。我在我的应用程序中使用了更简单的东西:
希望它能帮助某人。
3 months later, but for the ones who want to know. I used something simpler in my applications :
Hope it will help somebody.