Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Lots of people have been talking about XML, it's a good idea. However, if Linq is available for you, you shoudl <strong>really</strong> consider using <a href="http://msdn.microsoft.com/en-us/library/bb387098.aspx" rel="nofollow noreferrer">Linq to XML</a> instead of SAX/DOM parsing.</p> <p>Linq to XML makes it easier to parse, create and edit XML file compared to SAX and DOM parser. Using SAX/DOM parsing usually requires a lot of loops to get to the correct element or to navigate trough the nodes.</p> <p>Example taken from MSDN :<br> Using DOM Parsing :</p> <pre><code>XmlDocument doc = new XmlDocument(); XmlElement name = doc.CreateElement("Name"); name.InnerText = "Patrick Hines"; XmlElement phone1 = doc.CreateElement("Phone"); phone1.SetAttribute("Type", "Home"); phone1.InnerText = "206-555-0144"; XmlElement phone2 = doc.CreateElement("Phone"); phone2.SetAttribute("Type", "Work"); phone2.InnerText = "425-555-0145"; XmlElement street1 = doc.CreateElement("Street1"); street1.InnerText = "123 Main St"; XmlElement city = doc.CreateElement("City"); city.InnerText = "Mercer Island"; XmlElement state = doc.CreateElement("State"); state.InnerText = "WA"; XmlElement postal = doc.CreateElement("Postal"); postal.InnerText = "68042"; XmlElement address = doc.CreateElement("Address"); address.AppendChild(street1); address.AppendChild(city); address.AppendChild(state); address.AppendChild(postal); XmlElement contact = doc.CreateElement("Contact"); contact.AppendChild(name); contact.AppendChild(phone1); contact.AppendChild(phone2); contact.AppendChild(address); XmlElement contacts = doc.CreateElement("Contacts"); contacts.AppendChild(contact); doc.AppendChild(contacts); </code></pre> <p>Using Linq to XML :</p> <pre><code>XElement contacts = new XElement("Contacts", new XElement("Contact", new XElement("Name", "Patrick Hines"), new XElement("Phone", "206-555-0144", new XAttribute("Type", "Home")), new XElement("phone", "425-555-0145", new XAttribute("Type", "Work")), new XElement("Address", new XElement("Street1", "123 Main St"), new XElement("City", "Mercer Island"), new XElement("State", "WA"), new XElement("Postal", "68042") ) ) ); </code></pre> <p>Easier to do and much more clear.</p> <p><strong>Edit:</strong><br> Save the XML tree to contacts.xml :</p> <pre><code>// using the code above contact.Save("contacts.xml"); </code></pre> <p>Load the contacts.xml file :</p> <pre><code>//using the code above XDocument contactDoc = XDocument.Load("contacts.xml"); </code></pre> <p>To update an element of the tree there is a few functions in the <a href="http://msdn.microsoft.com/en-us/library/bb387052.aspx" rel="nofollow noreferrer">doc</a> that can do it depending on what you want to do</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload