Linux command
xml-format 命令
文本
复制后可按需替换文件名、目录或参数。
常用示例
Format an XML file with default indentation
xml format [input.xml]
Format with a specific number of spaces for indentation
xml format --indent-spaces [4] [input.xml]
Format with tab indentation
xml format --indent-tab [input.xml]
Format and omit the XML declaration
xml format --omit-decl [input.xml]
Recover and format a malformed XML file
xml format --recover [input.xml]
Format to output file
xml format [input.xml] > [output.xml]
说明
xml format (also invoked as xml fo) pretty-prints XML documents. Part of the xmlstarlet toolkit. Reformats XML with proper indentation and line breaks for readability. Can also recover malformed XML and convert between encodings.
参数
- -n, --noindent
- Remove indentation from output.
- -t, --indent-tab
- Indent with tabs.
- -s _n_, --indent-spaces _n_
- Indent with n spaces.
- -o, --omit-decl
- Omit XML declaration.
- -D, --dropdtd
- Remove DTD declarations.
- -R, --recover
- Try to recover malformed XML.
- -C, --nocdata
- Convert CDATA sections to text nodes.
- -N, --nsclean
- Remove redundant namespace declarations.
- -e _encoding_, --encode _encoding_
- Output in specified encoding (e.g., utf-8).
- -H, --html
- Treat input as HTML.
FAQ
What is the xml-format command used for?
xml format (also invoked as xml fo) pretty-prints XML documents. Part of the xmlstarlet toolkit. Reformats XML with proper indentation and line breaks for readability. Can also recover malformed XML and convert between encodings.
How do I run a basic xml-format example?
Run `xml format [input.xml]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -n, --noindent do in xml-format?
Remove indentation from output.