Reading XML CDATA in windows 8 phone app

anon_945500

I am trying to read to some data in XML format which is CDATA in my windows 8 phone app. Here is a sample of the data:

<?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>

I want to get all the CDATA along with the corresponding VerseID. I need to do this in a windows 8 Phone app. Can anyone please show me how to correctly get this CDATA? I am trying Xdocument but I havent had much luck.

Thanks!

MarcinJuraszek

haven't had much luck does not tell much about your problems with XDocument, but I think it's still the best way to go:

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 is a list of anonymous type objects with two properties: Id with your VerseID value and Content with the CDATA content.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

TOP Ranking

HotTag

Archive