1
Answer

display data of xml file into multiple textblocks

maha lakshmi

maha lakshmi

12y
1.1k
1
Hii,cane anybody tell me how to display the data of xml into multiple textblocks?

this is my XML file :

<?xml version="1.0" encoding="utf-8" ?>
<Hadith>
  <Serial No="1">
    <Current Date="11 March 2011" 
             ArabicDate="10 Rabi-Ul-Awal 1434" 
             NarratedBy="Narrated Abdullah:"
             HadithBody=
             "Knowledge is of two types.Firstly,knowledge &#xD;
              perceived by the heart,and that is useful &#xD;
              knowledge;secondly,the knowledge at on the tip &#xD;
              of one's tongue,and that is an argument from &#xD;
              Allah,the Exalted and Glorious,against the &#xD;
              children of Adam."
              ReferencedVerses="TransmittedBy:"
              ReferencedBy="Darimi-Al-Timidhi-Hadith 270">
      
    </Current>
  </Serial>
  
</Hadith>



and i want to retrieve the all the value which i declared in xml file and i just to display each value in different textblocks..so now,i am using six textblocks?Can any body tell me how to do this?
Answers (1)
0
Vulpes

Vulpes

NA 98.3k 1.5m 12y
You can get a string array containing the 6 attribute values using LINQ to XML as follows:

using System.Linq;
using System.Xml.Linq;
using System.IO;

// ...

XElement root = XElement.Load("maha.xml");
string[] values = root.Element("Serial").Element("Current").Attributes().Select(a => 
a.Value).ToArray();

You should find that:

values[0] will contain : 11 March 2011
values[1] will contain : 10 Rabi-Ul-Awal 1434

and so on.

It's then just a matter of assigning the appropriate values to your textblocks.