我有一个 XML 文件,其格式非常压缩,所有标签都像
<PersonalData><IndividualDetails><Title>Mr</Title><Gender>Male</Gender><FirstName>Hae</FirstName><Surname>JONES</Surname><Occupation>Banker</Occupation><DateofBirth>4/6/76</DateofBirth><LastKnownAddress></LastKnownAddress><LastKnownPostCode>00145</LastKnownPostCode><OtherNames></OtherNames></IndividualDetails><OccupationDetails><Company>SD Bank</Company><CompanyAddress>Sunset Boulevard NY</CompanyAddress><ContactNo>335698457</ContactNo></OccupationDetails></PersonalData>
shell 中是否有任何命令可以正确格式化标签。如果不缩进只将标签添加到他们自己的行也可以解决我的问题。
最佳答案
xmllint --format <your-xml-file>
例子
$ cat test.xml
<a><b>c</b></a>
$ xmllint --format test.xml
<a>
<b>c</b>
</a>
$ xmllint --format test.xml > test.formatted.xml
$ cat test.formatted.xml
<a>
<b>c</b>
</a>
$
关于XML 格式化缩进标签匹配 - Linux,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11965347/