xml utility is a command-line tool for parsing, validating, and pretty-printing XML documents. It includes syntax highlighting support for terminal output.
Usage
Options
--color, -c- Enable syntax highlighting--only-contents, -o- Print only the content without XML tags
Features
XML parsing and validation
Parse and validate XML documents:Pretty printing
Format XML with proper indentation:Syntax highlighting
Enable colored output for better readability:- Tags - Bold yellow
- Attribute names - Blue
- Attribute values - Green
- Comments - Italic gray
- Processing instructions - Bold beige
- Text content - Default color
- Doctype declarations - Bold beige
- Keywords - Green
Content extraction
Extract only text content, stripping all XML tags:Input sources
Local files
URLs
The utility can fetch and parse XML from URLs:Standard input
Examples
Parse and display XML
Pretty print with color
Extract text content only
Validate XML from URL
XML features supported
- Elements and attributes
- Text nodes
- Comments
- Processing instructions
- DOCTYPE declarations
- CDATA sections
- Namespaces
Implementation details
The XML utility is built on:- LibXML: XML parsing and DOM implementation
- LibURL: URL parsing for remote documents
- LibCore: File I/O and argument parsing
~/workspace/source/Utilities/xml.cpp
The tool automatically handles both local files and remote URLs based on the input format.
When using
--only-contents, the output includes only text nodes, with comments and processing instructions stripped.