1 Reference an XML file
2. Use XMLReader to parse text strings
3. Use XMLReader to read XML data
The Code is as follows:
// Initialize an XML string
String xmlString = @ "<bookstore> <book genre = 'autoposition' publicationdate = '2017-03-22 'ISBN = '1-861003-11-0'> <title> The autobiography of Benjamin Franklin </ title> <author> <first-name> Benjamin </first-name> <last-name> Franklin </last-name> </author> <price> 8.99 </price> </book> </bookstore> "; parseXml (xmlString); static void ParseXml (string xmlString) {// create a StringBuilder object to save the parsed text content from the XML file StringBuilder output = new StringBuilder (); create an XML reader using (XmlReader reader = XmlReader. create (new StringReader (xmlString) {reader. readToFollowing ("book"); reader. moveToFirstAttribute (); string genre = reader. value; output. appendLine ("The genre value:" + genre); reader. readToFollowing ("title"); output. appendLine ("Content of the title element:" + reader. readElementContentAsString ();} Console. writeLine (output );}