How to format XML code in Ace editor?

I am using the ACE editor to display xml content on my web page. I want to format the XML in an editor.

Can someone tell me how to do this?

+3
source share
2 answers

Numerous modes are included in the package, and the Wiki on github will tell you how to implement it. Something like that:

var Mode = require('ace/mode/xml').Mode;
editor.getSession().setMode(new Mode());
+3
source

The formatting of the XML code is not specified in Ace itself, as it is just an editor. Use any of the answers to this question to prefix the code.

var code = ace.getSession().getValue();
// prettify
ace.getSession().setValue(code);
+14
source

All Articles