LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

xml-c14n

Canonicalize XML documents (xmlstarlet c14n)

TLDR

Inclusive canonicalization with comments (W3C XML C14N 1.0)
$ xml c14n --with-comments [file.xml]
copy
Inclusive canonicalization stripping comments
$ xml c14n --without-comments [file.xml]
copy
Exclusive canonicalization with comments (XML EXC-C14N)
$ xml c14n --exc-with-comments [file.xml]
copy
Exclusive canonicalization without comments
$ xml c14n --exc-without-comments [file.xml]
copy
Canonicalize a subset selected by an XPath expression file
$ xml c14n --without-comments [file.xml] [xpath.xml]
copy
Read from stdin
$ cat [file.xml] | xml c14n --with-comments -
copy

SYNOPSIS

xml c14n mode xml-file [xpath-file] [inclusive-ns-list]

DESCRIPTION

xml c14n is the canonicalization sub-command of xmlstarlet. It produces a byte-stable serialization of an XML document according to the W3C Canonical XML 1.0 or Exclusive XML Canonicalization 1.0 specifications. The result is what tools must compute before generating or verifying XML Digital Signatures (XML-DSig) so that semantically equivalent documents hash to the same value.Inclusive canonicalization includes ancestor namespace declarations; exclusive canonicalization (used by SAML, WS-Security, etc.) drops them unless explicitly listed in the inclusive namespace prefix list.

PARAMETERS

MODE (required, exactly one)

One of --with-comments, --without-comments, --exc-with-comments, --exc-without-comments.
XML-FILE
XML document to canonicalize. Use - to read stdin.
XPATH-FILE
Optional XML file whose root element's text content is an XPath expression that selects the node-set to canonicalize.
INCLUSIVE-NS-LIST
For exclusive C14N only: space-separated list of namespace prefixes to treat as inclusive (e.g. `'soap xsd'`).

INSTALL

sudo dnf install xmlstarlet
copy
sudo pacman -S xmlstarlet
copy
sudo apk add xmlstarlet
copy
sudo zypper install xmlstarlet
copy
brew install xmlstarlet
copy
nix profile install nixpkgs#xmlstarlet
copy

CAVEATS

The mode flag is positional — every invocation must supply exactly one of the four mode options before the input file. The XPath argument is itself an XML file containing an XPath, not a literal expression on the command line.

SEE ALSO

Copied to clipboard
Kai