<p>What is the best way to deal with XML documents, XSD etc in C# 2.0? </p>

<p>Which classes to use etc. What are the best practices of parsing and making XML documents etc. </p>

<p>EDIT: .Net 3.5 suggestions are also welcome.</p>

It depends on the size; for small to mid size xml, a DOM such as
XmlDocument
(any C#/.NET versions) or
XDocument
(.NET 3.5/C# 3.0) is the obvious winner. For using xsd, You can load xml using an
XmlReader
, and an XmlReader accepts (to
Create
) an
XmlReaderSettings
. The XmlReaderSettings objects has a
Schemas
property that can be used to perform xsd (or dtd) validation.
For writing xml, the same things apply, noting that it is a little easier to lay out content with LINQ-to-XML (XDocument) than the older XmlDocument.
However, for huge xml, a DOM may chomp too much memory, in which case you might need to use XmlReader/XmlWriter directly.
Finally, for manipulating xml you may wish to use
XslCompiledTransform
(an xslt layer).
The alternative to working with xml is to work with an object model; you can use
xsd.exe
to create classes that represent an xsd-compliant model, and simply load the xml
as objects
, manipulate it with OO, and then serialize those objects again; you do this with
XmlSerializer
.