How to check if xml file is valid in sh or bash?

How to check if an XML file is valid in sh (preferred) or bash?

I have a file that is often damaged and needs to be replaced until I rush to investigate the main problem.

Is there an easy way to accomplish this task with sh or bash?

+6
source share
4 answers

Not directly with bash, but xmllintquite widely available.

xmllint --format "${xmlfile}"

This will lead to termination with a non-zero status (hint: $?in bash it receives the exit code of the last command) if the xml file is invalid.

+13
source

RelaxNG, XML- W3C, Libxml2 (xmllint), XML RelaxNG.

XML Libxml2 RelaxNG

xmllint --noout --relaxng schema.rng file.xml

RelaxNG XML- trang. Jing XML- RelaxNG.

jing file.xml schema.relaxng :

jing schema.rng file.xml

RelaxNG:

jing -c schema.rnc file.xml
+2

XMLStarlet validate. , :

xmlstarlet val "$filename"

DTD:

xmlstarlet val -d "$dtd_filename" "$xml_filename"

XSD:

xmlstarlet val -s "$xsd_filename" "$xml_filename"

RelaxNG:

xmlstarlet val -r "$rng_filename" "$xml_filename"

bash - bash XML, - .


XMLStarlet XML, XML .. XML , .

+1

, . , .

0

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


All Articles