Thursday, May 4, 2017

Check if an XML file is well-formed in Linux

Do you want to know if a particular XML file is well-formed or malformed in Linux? Consider using xmllint.

If the return result is 0, then the XML file is well-formed:
oracle@soahost1:/tmp> xmllint --noout config.xml; echo $? 
0

If the return result is 1, then the XML is malformed:
oracle@soahost1:/tmp> xmllint --noout config.xml; echo $? 
config.xml:7: parser error : Opening and ending tag mismatch: domain line 2 and configuration-property 
  </configuration-property> 
                           ^ 
config.xml:8: parser error : Extra content at the end of the document 
  <domain-version>12.2.1.1.0</domain-version> 
  ^ 
1

If you want to recursively check all XML files, this command will do it for you:

for i in `find . -name "*.xml"`; do echo $i; xmllint --noout $i; echo $?; done




2 comments:

high technologies solutions said...

A big thank you for posting this content by the way if you are looking for best tally institute in delhi so contact here +91-9311002620 visit https://www.htsindia.com/Courses/tally/tally-training-course

Dreamsoft Consultants said...

Your post is really good thanks for sharing these kind of post but if anyone looking for Best Consulting Firm for Fake Experience Certificate Providers in pune, India with Complete Documents So Dreamsoft Consultancy is the Best Place.Further Details Here- 9599119376 or VisitWebsite-https://experiencecertificates.com/experience-certificate-provider-in-pune.html