Home » 2014 » April » 22 » xmllint : a command line xml tool to view and find errors in XML file

7:50 PM
xmllint : a command line xml tool to view and find errors in XML file

DESCRIPTION
       The xmllint program parses one or more XML files, specified on the command line as XML-FILE (or the standard input if the filename provided is - ). It prints various types of output, depending upon the options selected. It is useful for detecting errors both in XML code and in the XML parser itself.
Mostly used options:
   --format
              Reformat and reindent the output. The XMLLINT_INDENT environment variable controls the indentation. The default value is two spaces " ").
  --noout
              Suppress output. By default, xmllint outputs the result tree.

 --path "PATH(S)"
              Use the (space- or colon-separated) list of filesystem paths specified by PATHS to load DTDs which is used to valiidate the xml file. Enclose space-separated lists by quotation marks.

 --valid
              Determine if the document is a valid instance of the included Document Type Definition (DTD). A DTD to be validated against also can be specified at the command line using the --dtdvalid option. By default, xmllint also checks to determine if the document is well-formed.

 --dtdvalid URL
              Use the DTD specified by an URL for validation.

Example:

xmllint --format xml-file

The above command will open the xml file in xml format if it is not having any formatting error. So, if the file is having some error it will not open and throw error.

Prompt:>xmllint --format 140422_121243_L1003_DA_14677_1_1.xml
140422_121243_L1003_DA_14677_1_1.xml:1: parser error : PCDATA invalid Char value 19
 Otomotiv</line1><line2>Ithalat ve Dagitim A. S.</line2><line3>Att. Y. Bilgin/Ã
                                                                               ^
140422_121243_L1003_DA_14677_1_1.xml:1: parser error : PCDATA invalid Char value 19
 Otomotiv</line1><line2>Ithalat ve Dagitim A. S.</line2><line3>Att. Y. Bilgin/à                                                                             

xmllint --path /home/user/DTD --VALID xml-file

The above command will validate the xml file against the DTD file mentioned in the command.

Now suppose you have opned an XML file in VI editor so it will be unreadable. To format the content in XML inside VI editor only, we can use below command:

:% !xmllint % --format

So the above command will make the content readabe by showing it in XML format.

 
 

Category: Open System-Linux | Views: 2542 | Added by: shanky | Tags: format check of xml file in linux, xmllint inside vi editor, validating xml file in linux, xmllint command in linux | Rating: 5.0/1

Related blogs


You may also like to see:


[2014-12-05][Open System-Linux]
PIDSTAT command for debugging and analysis of Performance of Linux process
[2014-09-21][Open System-Linux]
How to define command prompt strings in Linux : what are $PS1, $PS2, $PS3 and $PS4?
[2016-03-17][Open System-Linux]
Some amazing command shortcuts in Linux
[2014-03-13][Open System-Linux]
crontab: A command in linux to automatically start/repeat a process at certian time and interval
[2015-06-19][Open System-Linux]
How to create swap file in Linux : Adding extra swap space

Total comments: 0
ComForm">
avatar