In emacs XML mode, how can I format an XML schema file?

I want to automatically format the XML schema definition file. All normal printed materials: linebreaks after end-element, indentiing. I saw this answer and this elisp that gives me the basics. However, besides what it is, I would like line breaks between attributes in square brackets.

Same. Before:

<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>

After:

<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>

Can someone suggest some elisp that can line the string =?

+3
source share
1 answer

Try the following:

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

, ( ), , , .

+2

Source: https://habr.com/ru/post/1709199/


All Articles