xml-edit
Edit XML files from the command line
TLDR
Delete elements matching an XPATH from an XML document
Move an element node of an XML document from XPATH1 to XPATH2
Rename all attributes named "id" to "ID"
Rename sub-elements of the element "table" that are named "rec" to "record"
Update the XML table record with "id=3" to the value "id=5"
Display help
SYNOPSIS
`xml-edit` [OPTIONS] input-file [output-file]
Alternatively, it might support piped input:
`cat input-file | xml-edit [OPTIONS] > output-file`
PARAMETERS
-x xpath-expression, --xpath xpath-expression
Specifies an XPath expression to select the target nodes or attributes for the operation.
-s value, --set-value value
Sets the text content of the selected element or the value of the selected attribute to the specified value.
-A name=value, --add-attribute name=value
Adds a new attribute with the given name and value to the selected element(s). If the attribute already exists, its value is updated.
-D, --delete
Deletes the nodes or attributes selected by the XPath expression.
-N element-name, --new-element element-name
Creates a new element with element-name under the node selected by XPath. Can be combined with -s or -A to set initial content/attributes.
-i, --in-place
Modifies the input file directly, overwriting its original content. Caution is advised when using this option.
-o file, --output file
Directs the modified XML output to the specified file instead of standard output.
-P, --pretty-print
Reformats the output XML with proper indentation and line breaks for human readability.
-h, --help
Displays a help message and exits.
DESCRIPTION
The `xml-edit` command is conceived as a powerful, versatile command-line utility designed for modifying XML documents non-interactively.
While `xml-edit` is not a standard, universally distributed Linux command, its conceptual role is to provide capabilities for scripting and automating XML transformations. It would typically allow users to select specific nodes or attributes within an XML file using XPath expressions, and then perform various operations such as setting new values, adding or deleting elements and attributes, or reformatting the XML structure.
Such a tool is invaluable for tasks like configuration file management, data transformations in build pipelines, or batch processing of XML datasets, enabling precise modifications without the need for GUI-based editors or complex scripting with general-purpose text tools.
CAVEATS
It is critical to note that `xml-edit` is not a standard or widely available Linux command-line utility in most distributions. This description outlines the conceptual functionality of such a tool, based on common needs for command-line XML manipulation.
Users seeking similar functionality should explore well-established alternatives such as:
Relying on a command named `xml-edit` without confirming its existence and specific implementation in your environment could lead to unexpected results.
HISTORY
While a specific `xml-edit` command does not have a documented history of widespread adoption, the need for robust command-line XML manipulation tools arose with the increasing use of XML for configuration, data exchange, and web services. This led to the development of various utilities like `xmlstarlet` and `xmllint` that provide similar programmatic editing capabilities, often used in shell scripts for automated tasks.
SEE ALSO
xmlstarlet(1), xmllint(1), jq(1), sed(1), awk(1)