xml file attributes accessing
-
Sunday, July 15, 2012 4:11 AM
Hello
will anyone please help me about loading attributes from the following xml pattern file. what i need is to take aya "text" value into a textbox (or any output panel) with sura index,name and aya index and text. Thanks in advance.
---------------I'm using visual basic.net (express 2010)-----------------------------
<quran>
<sura index="1" name="الفاتحة">
<aya index="1" text="بسم الله الرحمن الرحيم" />
<aya index="2" text="الحمد لله رب العالمين" />
<aya index="3" text="الرحمن الرحيم" />
<aya index="4" text="مالك يوم الدين" />
<aya index="5" text="إياك نعبد وإياك نستعين" />
<aya index="6" text="اهدنا الصراط المستقيم" />
<aya index="7" text="صراط الذين أنعمت عليهم غير المغضوب عليهم ولا الضالين" />
</sura>
<sura index="2" name="البقرة">
<aya index="1" text="الم" bismillah="بسم الله الرحمن الرحيم" />
<aya index="2" text="ذلك الكتاب لا ريب فيه هدى للمتقين" />................... goes to the end in the same manner------------------
</sura>
</quran>
any help will be appreciated.
when i use following code with the schema, it returns empty
MsgBox(xml...<xs:complexType>.<xs:choice>.<xs:sequence>.<xs:attribute>.<text>.Value)
- Edited by Saleemnoori Sunday, July 15, 2012 4:14 AM
- Edited by Saleemnoori Sunday, July 15, 2012 4:17 AM
- Edited by Saleemnoori Sunday, July 15, 2012 4:18 AM
- Edited by Saleemnoori Sunday, July 15, 2012 4:34 AM MsgBox(xml...<xs:complexType>.<xs:choice>.<xs:sequence>.<xs:attribute>.<text>.@Value)
- Edited by Saleemnoori Sunday, July 15, 2012 4:35 AM
All Replies
-
Sunday, July 15, 2012 4:40 PM
Hi Saleemnoori;
The below code snippet will get the info from the XML so that you may place it into what ever control you need.' Your XML Document
<quran> <sura index="1" name="الفاتحة"> <aya index="1" text="بسم الله الرحمن الرحيم" /> <aya index="2" text="الحمد لله رب العالمين" /> <aya index="3" text="الرحمن الرحيم" /> <aya index="4" text="مالك يوم الدين" /> <aya index="5" text="إياك نعبد وإياك نستعين" /> <aya index="6" text="اهدنا الصراط المستقيم" /> <aya index="7" text="صراط الذين أنعمت عليهم غير المغضوب عليهم ولا الضالين" /> </sura> <sura index="2" name="البقرة"> <aya index="1" text="الم" bismillah="بسم الله الرحمن الرحيم" /> <aya index="2" text="ذلك الكتاب لا ريب فيه هدى للمتقين" /> ................... goes to the end in the same manner------------------ </sura> </quran>
' Linq query to select the nodes and attributes Dim results = From q in elements.Descendants("sura") Select New With { .Sura = q.Attribute("index").Value, .Name = q.Attribute("name").Value, .AyaInfo = q.Elements("aya").Select(Function(a) New With { .Index = a.Attribute("index").Value, .Text = a.Attribute("text").Value }) } ' Iterate over the results of the query. ' This is where you can fill your text box or other control. For Each sura in results ' Get the sura node info and display Console.WriteLine("Sura index = {0} Name = {1}", sura.Sura, sura.Name) For Each aya in sura.AyaInfo ' Get the aya node info and display Console.WriteLine( " Aya index = {0} Text = {1}", aya.Index, aya.Text) Next Next
Fernando (MCSD)
If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".- Marked As Answer by Saleemnoori Wednesday, August 08, 2012 5:53 PM

