From 534dc1ab212fbb1bea9de11875843afdfcbd1edb Mon Sep 17 00:00:00 2001 From: cyqsimon <28627918+cyqsimon@users.noreply.github.com> Date: Wed, 17 May 2023 01:00:50 +0800 Subject: [PATCH] xmlstarlet: add page (#9952) * xmlstarlet: add page --------- Co-authored-by: Jack Lin --- pages/common/xmlstarlet.md | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 pages/common/xmlstarlet.md diff --git a/pages/common/xmlstarlet.md b/pages/common/xmlstarlet.md new file mode 100644 index 000000000..29a45132c --- /dev/null +++ b/pages/common/xmlstarlet.md @@ -0,0 +1,37 @@ +# xmlstarlet + +> A commandline XML/XSLT toolkit. +> Note: You will likely need to know XPath: . +> More information: . + +- Format an XML document and print to stdout: + +`xmlstarlet format {{path/to/file.xml}}` + +- XML document can also be piped from stdin: + +`{{cat path/to/file.xml}} | xmlstarlet format` + +- Print all nodes that match a given XPath: + +`xmlstarlet select --template --copy-of {{xpath}} {{path/to/file.xml}}` + +- Insert an attribute to all matching nodes, and print to stdout (source file is unchanged): + +`xmlstarlet edit --insert {{xpath}} --type attr --name {{attribute_name}} --value {{attribute_value}} {{path/to/file.xml}}` + +- Update the value of all matching nodes in place (source file is changed): + +`xmlstarlet edit --inplace --update {{xpath}} --value {{new_value}} {{file.xml}}` + +- Delete all matching nodes in place (source file is changed): + +`xmlstarlet edit --inplace --delete {{xpath}} {{file.xml}}` + +- Escape or unescape special XML characters in a given string: + +`xmlstarlet [un]escape {{string}}` + +- List a given directory as XML (omit argument to list current directory): + +`xmlstarlet ls {{path/to/directory}}`