<p>Anyone got a ready made function that will take an XML string and return a correctly indented string?</p>

<p>eg</p>

<pre><code>&lt;XML&gt;&lt;TAG1&gt;A&lt;/TAG1&gt;&lt;TAG2&gt;&lt;Tag3&gt;&lt;/Tag3&gt;&lt;/TAG2&gt;&lt;/XML&gt;
</code></pre>

<p>and will return nicely formatted String in return after inserting linebreaks and tabs or spaces?</p>

Using
OmniXML
:
```
```
program TestIndentXML;

{$APPTYPE CONSOLE}

uses
  SysUtils,
  OmniXML,
  OmniXMLUtils;

function IndentXML(const xml: string): string;
var
  xmlDoc: IXMLDocument;
begin
  Result := '';
  xmlDoc := CreateXMLDoc;
  if not XMLLoadFromAnsiString(xmlDoc, xml) then
    Exit;
  Result := XMLSaveToAnsiString(xmlDoc, ofIndent);
end;

begin
  Writeln(IndentXML('<XML><TAG1>A</TAG1><TAG2><Tag3></Tag3></TAG2></XML>'));
  Readln;
end.
```
```
The code fragment above is released to public domain.