Installing Xmllint on Windows

Xmllint is a command-line tool used to parse and validate XML files. It is a part of the libxml2 library, which is a widely-used C library for parsing and manipulating XML files. In this guide, we will walk through the steps to install xmllint on Windows.

Prerequisites

  • Windows 10 or later (64-bit or 32-bit)
  • Internet connection

Method 1: Installing Xmllint using Chocolatey

Chocolatey is a popular package manager for Windows. Here's how to install xmllint using Chocolatey:

  1. Install Chocolatey: Open PowerShell as an administrator and run the following command:
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
  1. Install Xmllint: Once Chocolatey is installed, run the following command to install xmllint:
choco install libxml2

This will install the libxml2 library, which includes xmllint.

  1. Verify Xmllint Installation: Open a new Command Prompt or PowerShell window and type:
xmllint --version

You should see the version of xmllint installed on your system.

Method 2: Installing Xmllint using MinGW

MinGW is a free and open-source software development environment for Windows. Here's how to install xmllint using MinGW:

  1. Download and Install MinGW: Go to the MinGW website (www.mingw.org) and download the installer. Run the installer and follow the prompts to install MinGW.
  2. Install Xmllint: During the installation process, select the "mingw32-libxml2" package, which includes xmllint.
  3. Add MinGW to System PATH: After installation, add the MinGW bin directory to your system PATH environment variable. Right-click on "Computer" or "This PC" and select "Properties" > "Advanced system settings" > "Environment Variables". Under "System Variables", scroll down and find the "Path" variable, then click "Edit". Click "New" and enter the path to the MinGW bin directory (e.g., C:\MinGW\bin).
  4. Verify Xmllint Installation: Open a new Command Prompt or PowerShell window and type:
xmllint --version

You should see the version of xmllint installed on your system.

Method 3: Installing Xmllint using Windows Subsystem for Linux (WSL)

If you have Windows 10 or later, you can install xmllint using the Windows Subsystem for Linux (WSL). Here's how:

  1. Enable WSL: Open PowerShell as an administrator and run the following command:
Enable-WindowsOptionalFeature -FeatureName Microsoft-Windows-Subsystem-for-Linux
  1. Install a Linux Distribution: Go to the Microsoft Store and install a Linux distribution (e.g., Ubuntu).
  2. Launch Linux Distribution: Launch the Linux distribution from the Start menu.
  3. Install Xmllint: Run the following command to install xmllint:
sudo apt-get install libxml2-utils
  1. Verify Xmllint Installation: Type:
xmllint --version

You should see the version of xmllint installed on your system.

Conclusion

In this guide, we have walked through three methods to install xmllint on Windows: using Chocolatey, MinGW, and Windows Subsystem for Linux (WSL). Xmllint is a useful tool for parsing and validating XML files, and we hope this guide has helped you to install it on your Windows system.


Which Installation Method Should You Choose?

| Method | Difficulty | Best For | |--------|------------|-----------| | Pre-built binaries | Easy | Single‑file, no extra tools needed | | Chocolatey | Easy | Package manager users | | MSYS2 | Medium | Developers already using Git Bash/MinGW | | WSL | Medium | Linux fans on Windows | | Cygwin | Medium | Users needing many Unix tools |

For most Windows users, Method 1 (pre-compiled binaries) or Method 2 (Chocolatey) is the fastest and most reliable. If you work regularly with Unix tools, MSYS2 or WSL will serve you better in the long run.


Example 1: Format an XML file

xmllint --format dirty.xml > clean.xml

“Fatal error: cannot load external entity”

  • Cause: Xmllint cannot find the specified file (relative path issue) or the XML is invalid.
  • Solution: Use absolute paths (e.g., C:\test\file.xml) or navigate to the file’s directory first.

Step 1: Download the Libxml2 Binary Package

Visit the official GitHub repository for Windows builds:
👉 https://github.com/mlocati/gettext-iconv-windows (look for the libxml2 release)

Alternatively, use the classic Zlatko’s site:
👉 https://www.zlatkovic.com/pub/libxml/ (though less frequently updated, it still works).

For the most up-to-date:

  1. Go to https://github.com/msys2/MINGW-packages but that’s source. Instead, directly download from mlocati’s builds:
    • Navigate to https://github.com/mlocati/libxml2-windows/releases
    • Download the latest libxml2-[version]-win64.zip (or win32 for 32-bit)
  2. Extract the ZIP file to a folder, e.g., C:\tools\libxml2

Test 2: Validate a simple XML file

Create a file called test.xml:

<?xml version="1.0"?>
<root>
    <item>Hello</item>
</root>

Run:

xmllint --noout test.xml

No output means the XML is well-formed.

Method 5: Using Chocolatey (Package Manager)

If you use Chocolatey for Windows software management:

Step 2: Install Xmllint via Chocolatey

Once Chocolatey is ready, install xmllint:

choco install libxml2

This installs the entire libxml2 package, including xmllint.exe. Chocolatey automatically adds the binary to your PATH.