Are you need IT Support Engineer? Free Consultant

How to validate a very Large XML using Command Line in Linux

  • By Nitin Jain
  • January 18, 2023
  • 365 Views

There are times when the XML File is very large and due to some special character the file is breaking. It is humanely impossible to check the file in an editor and identify the error. In our case it was a 1GB+ file which was having some issue in the Google Feed being created. As a result, Google was rejecting the file. For this purpose use xmllint. If you do not have it then install it using:

sudo apt-get install libxml2-utils

Then run the following command to validate XML

xmllint –noout file.xml

In order to check the validation programmatically:

Check for return code of this command. See documentation. Value of 1 is returned when basic parsing errors are met. E.g.:

echo $?

Documentation can be found here: http://xmlsoft.org/xmllint.html#Error%20Return%20Codes