我想自动格式化一个xml模式定义文件。所有正常的漂亮打印材料:结束元素后换行,缩进。我已经看到了this answer和this elisp,这给了我基本的知识。不过,除了这些之外,我还希望在尖括号内的属性之间换行。
像这样。之前:
<s:schema elementFormDefault="qualified" targetNamespace="urn:Cheeso.2009.05.Finance/TransferObject/TransactionDetail/" xmlns:tns="urn:Cheeso.2009.05.Finance/TransferObject/TransactionDetail/" xmlns:detail="urn:Cheeso.2009.05.Finance/TransferObject/TransactionDetail/" xmlns:to="urn:Cheeso.2009.05.Finance/TransferObject/" xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:address="urn:Cheeso.2009.05.Finance/TransferObject/Address/" xmlns:caller="urn:Cheeso.2009.05.Finance/TransferObject/Caller/" xmlns:gwy="urn:Cheeso.2009.05.Finance/TransferObject/Gateway/" xmlns:tender="urn:Cheeso.2009.05.Finance/TransferObject/Tender/" >
...
</s:schema>
后:
<s:schema
elementFormDefault = "qualified"
targetNamespace = "urn:Cheeso.2009.05.Finance/TransferObject/TransactionDetail/"
xmlns:tns = "urn:Cheeso.2009.05.Finance/TransferObject/TransactionDetail/"
xmlns:detail = "urn:Cheeso.2009.05.Finance/TransferObject/TransactionDetail/"
xmlns:to = "urn:Cheeso.2009.05.Finance/TransferObject/"
xmlns:s = "http://www.w3.org/2001/XMLSchema"
xmlns:address = "urn:Cheeso.2009.05.Finance/TransferObject/Address/"
xmlns:caller = "urn:Cheeso.2009.05.Finance/TransferObject/Caller/"
xmlns:gwy = "urn:Cheeso.2009.05.Finance/TransferObject/Gateway/"
xmlns:tender = "urn:Cheeso.2009.05.Finance/TransferObject/Tender/" >
...
</s:schema>
有人能给我推荐一个能把=?
最佳答案
尝试以下方法:
(defun prettyprint-xml ()
(interactive)
(goto-char (point-min))
(while (search-forward "=" (point-max) t)
(search-forward "\"")
(search-forward "\"")
(forward-char)
(newline-and-indent))
(align-regexp (point-min) (point-max) "\#"))
它可能不完全符合你的要求(我只是把它编码了),但它看起来应该适合你展示的案例。