To pretty print XML from the command line in Linux, you can use the xmllint
tool, which is part of the libxml2-utils
package. Here's how you can install and use it:
Install
libxml2-utils
package (if not already installed):sudo apt-get install libxml2-utils
Once installed, you can use the
xmllint
tool with the--format
option to pretty print XML files. Here's the basic syntax:xmllint --format input.xml
Replace
input.xml
with the path to your XML file.Running the command will print the prettified XML to the terminal. If you want to save the formatted XML to a file, you can redirect the output to a file using the
>
operator. For example:xmllint --format input.xml > output.xml
This command will save the prettified XML to
output.xml
.
Using xmllint
with the --format
option ensures that the XML is indented and formatted with line breaks for better readability.
Comments
Post a Comment