0

I have following xml How can I read xml to get list of Sura nodes like this


var Suras = XMLNodes **//how to use xpath to load xmlnodes of sura**

foreach (var sura in suras)
{
    var ayas =  sura. **//how to use xpath to load xmlnodes of aya for this sura node**
}

XML

<?xml version="1.0" encoding="utf-8" ?>
<quran>
  <sura index="1" name="الفاتحة">
    <aya index="1" text="In the name of Allah, the Entirely Merciful, the Especially Merciful."/>
    <aya index="2" text="[All] praise is [due] to Allah, Lord of the worlds -"/>
  </sura>
  <sura index="114" name="الناس">
    <aya index="1" text="Say, &quot;I seek refuge in the Lord of mankind,"/>
    <aya index="2" text="The Sovereign of mankind."/>
    <aya index="3" text="The God of mankind,"/>
    <aya index="4" text="From the evil of the retreating whisperer -"/>
    <aya index="5" text="Who whispers [evil] into the breasts of mankind -"/>
    <aya index="6" text="From among the jinn and mankind.&quot;"/>
  </sura>
</quran>

1 Answer 1

2

Do you particularly want to use XPath? I'd just use LINQ to XML:

XDocument doc = XDocument.Load("file.xml");
var suras = doc.Root.Elements("sura");
foreach (var sura in suras)
{
    var ayas = suras.Elements("aya");
    ...
}
Sign up to request clarification or add additional context in comments.

1 Comment

Yes want to use without LINQ to XML. So it will work on .net 4 & 2 both.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.