從移除所有的空格文件然後用xmllint
$ sed 's/[[:space:]]//g' test.xml | xmllint --format -
<?xml version="1.0"?>
<T1>
<S1>D1</S1>
<S1>D2</S1>
<S2>D3</S2>
<S3>D4</S3>
</T1>
背景
正如@choroba指出,輸入數據就不是有效的XML文件格式,它:
$ cat test.xml
<T1>
<S1 > D1 </S1>
<S1>D2 </ S1>
<S2>D3 </S2>
<S3> D4</S3>
</T1 >
的xmllint命令狀態原因:
$ xmllint test.xml
test.xml:3: parser error : expected '>'
<S1>D2 </ S1>
^
test.xml:3: parser error : Opening and ending tag mismatch: S1 line 3 and unparseable
<S1>D2 </ S1>
^
test.xml:4: parser error : StartTag: invalid element name
<S2>D3 </S2>
^
test.xml:4: parser error : Opening and ending tag mismatch: T1 line 1 and S2
<S2>D3 </S2>
^
test.xml:5: parser error : Extra content at the end of the document
<S3> D4</S3>
^
+1用於提示xmllint – 2012-01-03 21:03:16