views:

131

answers:

1
string xmlText= "
                  <Person>
                     <Name>abc</Name>
                     <Age>22</Age>
                  </person>";

i want the values abc and 22 m using silverlight 4 and XmlTextReader is not available Thanks in advance

A: 

You can parse XML data in Silverlight by using either LINQ to XML or XmlReader.

Here's some example code that uses XmlReader. It's very simple and only works with the exact input string that you defined. But, it should be enough to get you on your way.

string xmlText= @"
                  <Person>
                    <Name>abc</Name>
                      <Age>22</Age>
                  </Person>";
// Create an XmlReader
using (XmlReader reader = XmlReader.Create(new StringReader(xmlText)))
{
  // Parse the file and display each of the nodes.
  while (reader.Read())
  {
    if (reader.Name == "Name" && reader.NodeType == XmlNodeType.Element)
    {
      // Advace to the element's text node
      reader.Read();
      // ... do what you want (you can get the value with reader.Value)
    }
    else if (reader.Name == "Age" && reader.NodeType == XmlNodeType.Element)
    {
      // Advace to the element's text node
      reader.Read();
      // ... do what you want (you can get the value with reader.Value)
    }
}

Here's an article with more details:

http://msdn.microsoft.com/en-us/library/cc188996(VS.95).aspx

Babak Ghahremanpour
thanks!! It worked for me
taher chhabrawala