3

I am using ACE Editor to display xml content on my web page. I want to format the xml code in Editor.

Can Any one tell me how to do this ?

ThisClark
  • 14,352
  • 10
  • 69
  • 100
Rohit Kumar
  • 1,018
  • 3
  • 12
  • 23

2 Answers2

15

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

var code = ace.getSession().getValue();
// prettify
ace.getSession().setValue(code);
Community
  • 1
  • 1
Jan Jongboom
  • 26,598
  • 9
  • 83
  • 120
4

There are numerous modes included in the package and the Wiki at github will tell you how to implement it. Something like this:

var Mode = require('ace/mode/xml').Mode;
editor.getSession().setMode(new Mode());
David Hellsing
  • 106,495
  • 44
  • 176
  • 212
  • i have used xml mode but i want something that can format xml content displayed in editor. Something which can work same as "Ctrl+shift+F" in eclipse to format code. – Rohit Kumar May 25 '12 at 12:33
  • 1
    Why did you accept the answer, if it does not answer your question? – scipper Aug 30 '21 at 05:42