Haven’t really touched XML for a fair few months now so by way of a refresher I worked through the excellent Pluralsight “Many Approaches To XML Processing” course. Notes below:-
Use XmlReader when reading LARGE documents from disk – does not read complete document. very fast – use when performance is an issue. You’d typically loop through each element reading (“ReadElementString”) into a stringbuilder.
XPath is more flexible – able to navigate and select nodes (“Similar to finding folders on a hard drive”) through XML.
Use XDocument (.Load) to read into memory complete XML document. You can use
XPath (XPathSelectElements(“//Employes”) then foreach through each element or Linq to select nodes. Xml to Linq is easier to read than XPath
Reads complete into memory – creates datatables
Read in XML document – loop through rows
Create a new DataSet then ReadXml on that object – Foreach through table’s rows. Can use search logic i.e ds.Tables.Select(“LastName LIKE ‘s%’);
ReadXmlSchema will validate xml against XSD.