Monday, December 7, 2015

Cherry pick stuff out of XML with an XmlReader in C#.

byte[] bytesData = Encoding.Default.GetBytes(_myXmlInStringFormat);
MemoryStream memoryStream = new MemoryStream(bytesData);
using (XmlReader xmlReader = XmlReader.Create(memoryStream))
{
   xmlReader.ReadToFollowing("Foo");
   _foo = xmlReader.ReadElementContentAsString("Foo", "");
   if (xmlReader.ReadToFollowing("Bar"))
   {
      _bar = xmlReader.ReadElementContentAsString("Bar", "");
   }
}

No comments:

Post a Comment