1

can anyone help me to extract the data from the given code & display it on the screen?

<?xml version="1.0" encoding="UTF-8"?>
<statuses type="array">
<status>
  <created_at>Sun Dec 19 14:19:35 +0000 2010</created_at>
  <id>16497871259383000</id>
  <text>RT</text>
</status>
 .
 .
 .
</statuses>

pls help.....

NakedBrunch
  • 48,713
  • 13
  • 73
  • 98
varshabhat
  • 11
  • 1
  • 2
  • possible duplicate of [Best practices to parse xml files?](http://stackoverflow.com/questions/55828/best-practices-to-parse-xml-files) – Alex K. Apr 28 '11 at 14:53
  • Look at http://stackoverflow.com/questions/55828/best-practices-to-parse-xml-files. – Nik Apr 28 '11 at 14:54

3 Answers3

1

First, create a Status class:

public class Status
{
   public string created_at { get; set; }
   public string id { get; set; }
   public string text { get; set; }
} 

Next, use Linq To XML to create a List of Status objects

List<Status> statusList = (from status in document.Descendants("status")
                           select new Status()
                            {
                               created_at = status.Element("created_at").Value,
                               id = status.Element("id").Value,
                               text = status.Element("text").Value
                            }).ToList();

Once you have the List of Status objects, it is trivial to add them in any way you like to your app.

NakedBrunch
  • 48,713
  • 13
  • 73
  • 98
0
        var document = new XmlDocument();
        document.LoadXml(xmlString);

        XmlNode rootNode = document.DocumentElement;

        foreach(var node in rootNode.ChildNodes)
        {
            //node is your status node. 
            //Now, just get children and pull text for your UI
        }
Gregory A Beamer
  • 16,870
  • 3
  • 25
  • 32
0

The minimum viable answer to your question.

XDocument doc = XDocument.Load("PurchaseOrder.xml");
Console.WriteLine(doc);

http://msdn.microsoft.com/en-us/library/bb343181.aspx

Thomas Langston
  • 3,743
  • 1
  • 25
  • 41