- Reference System.XML
 - Use XmlReader to parse the text string
 - Use XmlReader to read the xml data
 
string xmlString =
                @"<bookstore>
                    <book genre='autobox'
publishDate='2015-03-04'>
                        <title>Many
bottle</title>
                        <author>
                           
<firstName>David</firstName>
                           
<lastName>Baby<lastName> 
                        </author>
                    </book>
                  </bookstore>";
StringBuilder result = new StringBuilder();
using (XmlReader reader = XmlReader.Create(new StringReader(xmlString)))
{
   reader.ReadToFollowing("book");
   reader.MoveToFirstAttribute();
   string genre = reader.Value;
   result.AppendLine("Genre value :" +
genre);
   reader.ReadToFollowing("title");
   result.AppendLine("title element :" +
reader.ReadElementContentAsString());
}
Console.Write(result);

No comments:
Post a Comment