xmllint : a UNIX utility to check for badly-formed XML data

It’s now commonplace to send or receive data files in XML format. And some eBusiness Suite functionality relies on XML configurations files. For example, BI Publisher data definitions are XML-formatted, and if you try to upload a badly-formed data template file to a BI Publisher data definition, Oracle responds with:

Error: The uploaded file XXAP073_BW_USER_RIGHTS_INT_XDO_DATA_TEMPL.xml is invalid. The file should be in XML-DATA-TEMPLATE format.


Not very helpful.

However, there’s a useful UNIX utility that will parse an XML file, and highlight any badly-formed XML syntax. It’s called xmllint:

xmllint --noout ${XML_FILE} 

It will return 0 (zero) if the XML file contains well-formed XML data; if the XML is badly formed, xmllint will list the specific errors. For example…

bash:dave$ XML_FILE='XML_DATAFILE.xml';
bash:dave$ echo ${XML_FILE}
bash:dave$ xmllint  --noout ${XML_FILE}
XML_DATAFILE.xml:320: parser error : attributes construct error
      <element name='FIRST_NAME' value='FIRST_NAME'/>;
XML_DATAFILE.xml:320: parser error : Couldn't find end of Start Tag element line 320
      <element name='FIRST_NAME' value='FIRST_NAME'/>;

I’ve used this in file transfer interfaces, to check that the XML file being passed contains well-formed XML data, for example:

xmllint  --noout ${XML_FILE}

echo 'XML format validation result : ${VALIDATE_XML}'
if [ ${VALIDATE_XML} != 0 ]; then
  echo ' ';
  echo 'XML data is badly formed';

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s