Performance between XmlSerializer and XmlReader

  • Thread starter Thread starter Franz
  • Start date Start date
F

Franz

My application will only read the xml file at startup and write the xml file
rarely. I am now using XmlSerializer to read the xml file at startup. I want
to speed it up. Therefore, I consider XmlReader. However, I don't know what
the differences are in reading by these 2 classes.
 
Franz,

XmlSerializer is typically used for serializing/deserializing objects
to/from XML. Typically you have some object which you would like to save to
restore later on. If you do not serialize it to binary, then you would use
XmlSerializer to serialize the object o XML.

XmlReader is used for reading XML data. As MSDN states:
"Represents a reader that provides fast, non-cached, forward-only access
to XML data."

Basically use XmlReader if all you want to do is read in XML input. Just
remember that XmlReader is "non-cached, forward-only" so if you need to
access random XML elements, you won't be able to use XmlReader.

Eric
 
Back
Top