代码之家  ›  专栏  ›  技术社区  ›  Cheeso

在EmacsXML模式下,如何调整XML模式文件的格式?

  •  3
  • Cheeso  · 技术社区  · 15 年前

    我想自动格式化一个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>
    

    有人能推荐一些符合='的elisp吗?

    1 回复  |  直到 15 年前
        1
  •  2
  •   Nathaniel Flath    15 年前

    尝试如下操作:

    (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) "\#"))
    

    它可能不完全符合您的要求(我只是对其进行了编码),但看起来它应该适用于您展示的案例。