[英]Reading XML CDATA in windows 8 phone app
我正在嘗試讀取Windows 8手機應用程序中XML格式的一些數據,即CDATA。 這是數據示例:
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE HolyQuran [
<!ATTLIST HolyQuran TranslationID CDATA #REQUIRED>
<!ATTLIST HolyQuran Writer CDATA #REQUIRED>
<!ATTLIST HolyQuran Language CDATA #REQUIRED>
<!ATTLIST HolyQuran LanguageIsoCode CDATA #REQUIRED>
<!ATTLIST HolyQuran Direction (rtl|ltr) #REQUIRED>
<!ELEMENT HolyQuran (Chapter+)>
<!ATTLIST Chapter ChapterID CDATA #REQUIRED>
<!ATTLIST Chapter ChapterName CDATA #REQUIRED>
<!ELEMENT Chapter (Verse+)>
<!ATTLIST Verse VerseID CDATA #REQUIRED>
<!ELEMENT Verse (#PCDATA)>
]>
<!-- This SQL Query Generated at 22 November 2013 01:44 (UTC) from
www.qurandatabase.org -->
<HolyQuran TranslationID="59" Writer="Yusuf Ali" Language="English"
LanguageIsoCode="eng" Direction="ltr">
<Chapter ChapterID="1" ChapterName="The Opening">
<Verse VerseID="1"><![CDATA[In the name of Allah, Most Gracious, Most
Merciful.]]></Verse>
<Verse VerseID="2"><![CDATA[Praise be to Allah, the Cherisher and Sustainer
of the worlds;]]></Verse>
<Verse VerseID="3"><![CDATA[Most Gracious, Most Merciful;]]></Verse>
<Verse VerseID="4"><![CDATA[Master of the Day of Judgment.]]></Verse>
<Verse VerseID="5"><![CDATA[Thee do we worship, and Thine aid we seek.
]]></Verse>
<Verse VerseID="6"><![CDATA[Show us the straight way,]]></Verse>
<Verse VerseID="7"><![CDATA[The way of those on whom Thou hast bestowed Thy
Grace, those whose (portion) is not wrath, and who go
not astray.]]></Verse>
</Chapter>
</HolyQuran>
我想獲取所有CDATA以及相應的VerseID。 我需要在Windows 8 Phone應用中執行此操作。 誰能告訴我如何正確獲取此CDATA? 我正在嘗試Xdocument,但運氣不佳。
謝謝!
運氣不太好,並不能告訴您有關XDocument
的問題,但是我認為這仍然是最好的方法:
var xDoc = XDocument.Load("Input.xml");
var items = xDoc.Root
.Element("Chapter")
.Elements("Verse")
.Select(v => new
{
Id = (int)v.Attribute("VerseID"),
Content = (string)v
}).ToList();
items
是具有兩個屬性的匿名類型對象的列表:具有您的VerseID
值的Id
和具有CDATA
內容的Content
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.