Using tidyobj.pas as a wrapper for libtidy.dll, I used this code:
Tidy := TTidy.Create(nil);
try
Tidy.LoadConfigFile('tidy_xml_settings.txt');
s := Tidy.ParseString(Memo1.Lines.Text);
Memo2.Lines.Text := s;
finally
Tidy.Free;
end;
...where tidy_xml_settings.txt defines these tidy options:
input-xml: yes
output-xml: yes
indent-attributes: yes
It works well as it allows to pass the XML as a string as required.
Input XML was:
<svg version="1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 48 48" enable-background="new 0 0 48 48">
<path fill="#37474F" d="M41,38H7c-2.2,0-4-1.8-4-4V14c0-2.2,1.8-4,4-4h34c2.2,0,4,1.8,4,4v20C45,36.2,43.2,38,41,38z"/>
<path fill="#F3E5F5" d="M6,14v20c0,0.6,0.4,1,1,1h34c0.6,0,1-0.4,1-1V14c0-0.6-0.4-1-1-1H7C6.4,13,6,13.4,6,14z"/>
<polygon fill="#9C27B0" points="26,15 20.1,22 31.9,22"/>
<path fill="#9C27B0" d="M24,21v6c0,1.1-0.9,2-2,2s-2-0.9-2-2v-2h-4v2c0,3.3,2.7,6,6,6s6-2.7,6-6v-6H24z"/>
</svg>
And TIDY created this valid output XML:
<svg version="1"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 48 48"
enable-background="new 0 0 48 48">
<path fill="#37474F"
d="M41,38H7c-2.2,0-4-1.8-4-4V14c0-2.2,1.8-4,4-4h34c2.2,0,4,1.8,4,4v20C45,36.2,43.2,38,41,38z" />
<path fill="#F3E5F5"
d="M6,14v20c0,0.6,0.4,1,1,1h34c0.6,0,1-0.4,1-1V14c0-0.6-0.4-1-1-1H7C6.4,13,6,13.4,6,14z" />
<polygon fill="#9C27B0"
points="26,15 20.1,22 31.9,22" />
<path fill="#9C27B0"
d="M24,21v6c0,1.1-0.9,2-2,2s-2-0.9-2-2v-2h-4v2c0,3.3,2.7,6,6,6s6-2.7,6-6v-6H24z" />
</svg>