格式化XML文档我已经在大量以下XML标记。如何在Linux
<SERVICE>
<NAME>
sh_SEET15002GetReKeyDetails
</NAME>
<ID>642</ID>
</SERVICE>
我想要以下列方式获得此格式。我尝试过使用xmllint,但它不适合我。请提供帮助。
<SERVICE>
<NAME>sh_SEET15002GetReKeyDetails</NAME>
<ID>642</ID>
</SERVICE>
格式化XML文档我已经在大量以下XML标记。如何在Linux
<SERVICE>
<NAME>
sh_SEET15002GetReKeyDetails
</NAME>
<ID>642</ID>
</SERVICE>
我想要以下列方式获得此格式。我尝试过使用xmllint,但它不适合我。请提供帮助。
<SERVICE>
<NAME>sh_SEET15002GetReKeyDetails</NAME>
<ID>642</ID>
</SERVICE>
没有编程,您可以使用Eclipse XML Source Editor
。看看这个answer
顺便说你尝试过xmllint -format -recover nonformatted.xml > formated.xml
?
编辑:
你可以试试这个XMLStarlet Command Line XML Toolkit。
5. Formatting XML documents
====================================================
xml fo --help
XMLStarlet Toolkit: Format XML document
Usage: xml fo [<options>] <xml-file>
where <options> are
-n or --noindent - do not indent
-t or --indent-tab - indent output with tabulation
-s or --indent-spaces <num> - indent output with <num> spaces
-o or --omit-decl - omit xml declaration <?xml version="1.0"?>
-R or --recover - try to recover what is parsable
-D or --dropdtd - remove the DOCTYPE of the input docs
-C or --nocdata - replace cdata section with text nodes
-N or --nsclean - remove redundant namespace declarations
-e or --encode <encoding> - output in the given encoding (utf-8, unicode...)
-H or --html - input is HTML
-h or --help - print help
是的,我已经用它是不是在这种情况下工作的同command..but。如果可能的话可能会有一些shell脚本或XSLT做要紧的 – user2693992
检查编辑,并告诉我,你是成功还是失败。 – Reuben
XML FO --help LPX-00202:无法打开 “FO”(错误200) – user2693992
xmllint -format -recover nonformatted.xml > formated.xml
对于标签缩进:
export XMLLINT_INDENT=`echo -e '\t'`
对于四个空间缩进:
export XMLLINT_INDENT=\ \ \ \
你要带或不带编程格式化? – Reuben