Install xmllint on Ubuntu 26.04

Install xmllint on Ubuntu 26.04

The xmllint is a command-line tool included with the libxml2 package for validating, parsing, and formatting XML documents. It is commonly used to check XML syntax, format XML files, and simplify the inspection of structured XML data. This tutorial demonstrates how to install xmllint on Ubuntu 26.04.

Install xmllint

Run the following command to update the package lists:

sudo apt update

Install the libxml2-utils package, which provides the xmllint command:

sudo apt install -y libxml2-utils

Confirm that the xmllint utility is available by displaying its version information:

xmllint --version

Testing xmllint

Create a sample XML file for testing:

nano test.xml

Add the following content:

<root>
<foo>bar</foo>
    <list>
<item>a</item>
        <item>b</item>
    <item>c</item>
</list>
      <nested>
    <x>1</x>
        <y>2</y>
</nested>
</root>

Format the XML document and overwrite the original file:

xmllint --format test.xml --output test.xml

The formatted file should appear as follows:

<?xml version="1.0"?>
<root>
  <foo>bar</foo>
  <list>
    <item>a</item>
    <item>b</item>
    <item>c</item>
  </list>
  <nested>
    <x>1</x>
    <y>2</y>
  </nested>
</root>

Uninstall xmllint

To remove xmllint when it is no longer needed, uninstall the package from the system:

sudo apt purge --autoremove -y libxml2-utils

Leave a Comment

Cancel reply

Your email address will not be published.