What is the most efficient way to deserialize an XML file

Aloha

I have an 8 MB XML file that I want to deserialize. I am using this code:

public static T Deserialize<T>(string xml)
{
    TextReader reader = new StringReader(xml);
    Type type = typeof(T);
    XmlSerializer serializer = new XmlSerializer(type);
    T obj = (T)serializer.Deserialize(reader);
    return obj; 
}

This code works in about a minute, which seems pretty slow to me. I tried using sgen.exe to precompile the dll serialization, but this did not change the performance.

What other options to improve performance?

[edit] I need an object that is created by deserialization to perform (basic) transformations. XML is obtained from an external web service.

+3
source share
3 answers

XmlSerializer , , , .

DOM XML- XmlDocument XDocument XmlReader. XmlReader - - .

, XML. ?

+3

, , - . 8mb... , . , .

, - XmlReader XPath . , -, XML XML...? .

, , , .

. , .

, .

+2

You can try to implement IXmlSerializable in your class T to process XML.

+1
source

Source: https://habr.com/ru/post/1702692/


All Articles