Windows Phone 7:将网站XML解析为XDocument [英] Windows Phone 7 : Parsing website XML into XDocument

查看:55
本文介绍了Windows Phone 7:将网站XML解析为XDocument的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎在尝试从网站解析XML的WP7上遇到问题.由于某种原因,它永远不会填充呼叫.没有错误,xml看起来不错,我指定了NS,但仍然没有.

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.

我在这里错过了一些非常简单的事情吗? 4小时后,我在桌子上敲打头.

Am I missing something really simple here? 4 hours in and I am banging my head on the desk.

我的C#技能只有2个月大,所以可能是我(大概是).

My C# skills are 2 months old, so it could be me (probably will be).

这是我用来解析从网站接收到的XML的代码...

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

这是我要解析的XML.

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>

推荐答案

那些'-''字符看起来很可疑.他们不应该在那里. (...虽然这可能是从浏览器中剪切出的人工痕迹)

Those '-' characters look suspect. They shouldn't be there. (...although this might be an artefact of cut'n'paste from the browser)

这篇关于Windows Phone 7:将网站XML解析为XDocument的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆