Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How expensive is a XSD validation of XML?

I want to validate large xml files by using xsd schemas in C#. For a file of 1000 lines of xml code validation takes a long time.

Are there any tips and tricks to validate faster?

Can you post some code examples that work faster with large xml validation?

Edit 1 : I validate like this Validating XML with XSD

Edit 2: For large files takes more than 10 seconds. And I need the validation to be very fast under a second.

Edit 3: File size is greater than 10 Mb

Edit 4: I am considering this approach too, I want to store xml file in database and xsd too.

like image 316
radu florescu Avatar asked Jan 23 '26 01:01

radu florescu


1 Answers

You are currently loading the entire document into memory, which is expensive regardless of validation. A better option is to just parse via a reader, i.e. as shown here on MSDN. The key points from the example on that page:

  • it never loads the entire document
  • the while(reader.Reader()) just enumerates the entire file at the node level
  • validation is enabled via the XmlReaderSettings
like image 169
Marc Gravell Avatar answered Jan 24 '26 13:01

Marc Gravell



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!