在 WinRT 中读取 XML

Reading XML in WinRT

我知道一个 XML 文件的网络 link,我正在我的应用程序中使用它。

它的根元素是 feed,它有几个名为 entry 的子元素。每个 entry 都有一个元素 summary,它由文本和几个子标签组成。例如,

<entry>
    <title type="text">money giving</title>
        <author>
        <name>BMA</name>
        </author>
    <summary type="text">
        <short-description>we give you money</short-description>
        <tab id="0" header="Header &amp; d">
        This is Line 1
        This is Line 2
        This is Line 3
        </tab>
        <tab id="1" header="abc">
        Only one line here
        </tab>
    </summary>
  </entry>

我想获取 summary 中的完整文本,包括子标签 short-descriptiontags。我试过使用这段代码:

XmlDocument xmlDoc = await XmlDocument.LoadFromUriAsync(new Uri("http://bigmanani.com/Kiosk-RSS_updated.xml"));
XDocument xDoc = XDocument.Parse(xmlDoc.GetXml());
XElement root = xDoc.Root;
XNamespace ad = "http://www.w3.org/2005/Atom";
IEnumerable<string> title = from abc in root.Descendants(ad+"summary") select (string )abc;

foreach(string one in title)
    DebugMessage(one);

问题是我只得到了 summary 元素的文本部分,而子元素 short-descriptiontab 被完全忽略了。我怎样才能获得完整的文本?

听起来您只是不想将转换为字符串,即 documented 为:

If the XElement has children, the concatenated string value of all of the element's text and descendant's text is returned.

您可能需要 ToString()

Returns the indented XML for this node.

所以:

var title = root.Descendants(ad + "summary").Select(x => x.ToString());

(仅对简单投影使用查询表达式没有任何好处 - 调用扩展方法更简单。)