Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

check XML syntax with xmllint

Tags:

xml

I am having a problem with some XML print files where the source system omits to convert some characters to their XML syntax equivalent (e.g. & is not converted to &).

Is there a way to catch this with xmllint? (I don't need to check the general tree structure using XSD).

like image 754
The GRAPKE Avatar asked Jul 24 '12 01:07

The GRAPKE


People also ask

How do I check if XML is valid in Linux?

By default xmllint "checks to determine if the document is well-formed". So, xmllint --noout --nonet goodfoo. xml will be comletely silent with an exit code of 0 for well-formed XML while xmllint --noout --nonet badfoo.

How do I validate an XML file?

XML documents are validated by the Create method of the XmlReader class. To validate an XML document, construct an XmlReaderSettings object that contains an XML schema definition language (XSD) schema with which to validate the XML document.

How do I check if XML is valid in Notepad ++?

After opening the XML file, go to the Plugins menu and you will now see the XML Tools option added to it. Simply go to the XML Tools > Validate Now option and click on it. You can also press Ctrl + Alt + Shift + M key combination to open Validate Now option.


1 Answers

xmllint --noout your_test_file.xml 

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

echo $? 
like image 85
Jarekczek Avatar answered Sep 21 '22 15:09

Jarekczek