我想自动格式化一个或多个OS X / macOS XML属性列表文件以使用像在其上运行'xmllint --format
'所得到的格式,除了:
<data>
'值的键将它们分成多行。 我还希望所有自闭合标签在其斜杠前都有空格。我将使用哪种XSLT(编辑:或其他)转换来实现此目的?
根据要求,这是一个最小的工作示例(略微this piece of Apple documentation :)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Year Of Birth</key>
<integer>1965</integer>
<key>Pets' Names</key>
<array/>
<key>Picture</key>
<data>
PEKBpYGlmYFCPA==
</data>
<key>City of Birth</key>
<string>Springfield</string>
<key>Name</key>
<string>John Doe</string>
<key>Kids' Names</key>
<array>
<string>John</string>
<string>Kyra</string>
</array>
<key>Pangram</key>
<data>
VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIHRoZSBsYXp5IGRvZy4gIA
</data>
<key>FollowingKeyDataLengthIsInsane</key>
<true/>
<key>'Lorem Ipsum' Sample Text</key>
<data>
TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBpc2NpbmcgZWxpdCwg
c2VkIGRvIGVpdXNtb2QgdGVtcG9yIGluY2lkaWR1bnQgdXQgbGFib3JlIGV0IGRvbG9yZSBtYWdu
YSBhbGlxdWEuIFV0IGVuaW0gYWQgbWluaW0gdmVuaWFtLCBxdWlzIG5vc3RydWQgZXhlcmNpdGF0
aW9uIHVsbGFtY28gbGFib3JpcyBuaXNpIHV0IGFsaXF1aXAgZXggZWEgY29tbW9kbyBjb25zZXF1
YXQuIER1aXMgYXV0ZSBpcnVyZSBkb2xvciBpbiByZXByZWhlbmRlcml0IGluIHZvbHVwdGF0ZSB2
ZWxpdCBlc3NlIGNpbGx1bSBkb2xvcmUgZXUgZnVnaWF0IG51bGxhIHBhcmlhdHVyLiBFeGNlcHRl
dXIgc2ludCBv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5jLiBO
dWxsYW0gYXJjdS4gQWxpcXVhbSBjb25zZXF1YXQuIEN1cmFiaXR1ciBhdWd1ZSBsb3JlbSwgZGFw
aWJ1cyBxdWlzLCBsYW9yZWV0IGV0LCBwcmV0aXVtIGFjLCBuaXNpLiBBZW5lYW4gbWFnbmEgbmlz
bCwgbW9sbGlzIHF1aXMsIG1vbGVzdGllIGV1LCBmZXVnaWF0IGluLCBvcmNpLiBJbiBoYWMgaGFi
aXRhc3NlIHBsYXRlYSBkaWN0dW1zdC4=
</data>
</dict>
</plist>
xmllint
输出的内容,在此示例中名为'sample.plist
:']的文件><?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>Year Of Birth</key> <integer>1965</integer> <key>Pets' Names</key> <array/> <key>Picture</key> <data> PEKBpYGlmYFCPA== </data> <key>City of Birth</key> <string>Springfield</string> <key>Name</key> <string>John Doe</string> <key>Kids' Names</key> <array> <string>John</string> <string>Kyra</string> </array> <key>Pangram</key> <data> VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIHRoZSBsYXp5IGRvZy4gIA </data> <key>FollowingKeyDataLengthIsInsane</key> <true/> <key>'Lorem Ipsum' Sample Text</key> <data> TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBpc2NpbmcgZWxpdCwg c2VkIGRvIGVpdXNtb2QgdGVtcG9yIGluY2lkaWR1bnQgdXQgbGFib3JlIGV0IGRvbG9yZSBtYWdu YSBhbGlxdWEuIFV0IGVuaW0gYWQgbWluaW0gdmVuaWFtLCBxdWlzIG5vc3RydWQgZXhlcmNpdGF0 aW9uIHVsbGFtY28gbGFib3JpcyBuaXNpIHV0IGFsaXF1aXAgZXggZWEgY29tbW9kbyBjb25zZXF1 YXQuIER1aXMgYXV0ZSBpcnVyZSBkb2xvciBp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yBuaXNsIGFkaXBpc2Npbmcgc2FwaWVuLCBzZWQgbWFsZXN1 YWRhIGRpYW0gbGFjdXMgZWdldCBlcmF0LiBDcmFzIG1vbGxpcyBzY2VsZXJpc3F1ZSBudW5jLiBO dWxsYW0gYXJjdS4gQWxpcXVhbSBjb25zZXF1YXQuIEN1cmFiaXR1ciBhdWd1ZSBsb3JlbSwgZGFw aWJ1cyBxdWlzLCBsYW9yZWV0IGV0LCBwcmV0aXVtIGFjLCBuaXNpLiBBZW5lYW4gbWFnbmEgbmlz bCwgbW9sbGlzIHF1aXMsIG1vbGVzdGllIGV1LCBmZXVnaWF0IGluLCBvcmNpLiBJbiBoYWMgaGFi aXRhc3NlIHBsYXRlYSBkaWN0dW1zdC4= </data> </dict> </plist>
这不是我想要的,但是为了完整性起见,我已经添加了它。]
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Year Of Birth</key>
<integer>1965</integer>
<key>Pets' Names</key>
<array />
<key>Picture</key>
<data>
PEKBpYGlmYFCPA==
</data>
<key>City of Birth</key>
<string>Springfield</string>
<key>Name</key>
<string>John Doe</string>
<key>Kids' Names</key>
<array>
<string>John</string>
<string>Kyra</string>
</array>
<key>Pangram</key>
<data>
VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIHRoZSBsYXp5IGRvZy4gIA
</data>
<key>FollowingKeyDataLengthIsInsane</key>
<true />
<key>'Lorem Ipsum' Sample Text</key>
<data>
TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBpc2NpbmcgZWxpdCwg
c2VkIGRvIGVpdXNtb2QgdGVtcG9yIGluY2lkaWR1bnQgdXQgbGFib3JlIGV0IGRvbG9yZSBtYWdu
YSBhbGlxdWEuIFV0IGVuaW0gYWQgbWluaW0gdmVuaWFtLCBx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2FwaWVuIHNlbSwgYWxpcXVldCBuZWMsIGNvbW1v
ZG8gZWdldCwgY29uc2VxdWF0IHF1aXMsIG5lcXVlLiBBbGlxdWFtIGZhdWNpYnVzLCBlbGl0IHV0
IGRpY3R1bSBhbGlxdWV0LCBmZWxpcyBuaXNsIGFkaXBpc2Npbmcgc2FwaWVuLCBzZWQgbWFsZXN1
YWRhIGRpYW0gbGFjdXMgZWdldCBlcmF0LiBDcmFzIG1vbGxpcyBzY2VsZXJpc3F1ZSBudW5jLiBO
dWxsYW0gYXJjdS4gQWxpcXVhbSBjb25zZXF1YXQuIEN1cmFiaXR1ciBhdWd1ZSBsb3JlbSwgZGFw
aWJ1cyBxdWlzLCBsYW9yZWV0IGV0LCBwcmV0aXVtIGFjLCBuaXNpLiBBZW5lYW4gbWFnbmEgbmlz
bCwgbW9sbGlzIHF1aXMsIG1vbGVzdGllIGV1LCBmZXVnaWF0IGluLCBvcmNpLiBJbiBoYWMgaGFi
aXRhc3NlIHBsYXRlYSBkaWN0dW1zdC4=
</data>
</dict>
</plist>
我想自动格式化一个或多个OS X / macOS XML属性列表文件,以使用像对它们运行'xmllint --format'一样的格式,除了:...
FWIW,这是您自己缩进输出的方法: