procedure Beautify(
const XML: IXMLDOMDocument;
const IndentString: WideString = #9);
procedure InsertFormattingNode(
const Node: IXMLDOMNode;
const Len,
Index: Integer; Break: Boolean = True);
var
I: Integer;
IndentStr: WideString;
begin
for I := 1
to Len
do
IndentStr := IndentStr + IndentString;
if Break
then
IndentStr := SLineBreak + IndentStr;
InsertTextNode(Node, IndentStr,
Index);
end;
procedure ProcessList(
const Node: IXMLDOMNode);
var
I: Integer;
Nesting: Integer;
begin
if not Assigned(Node)
then
Exit;
I := 0;
Nesting := GetNesting(Node);
while I < Node.childNodes.length
do
begin
if (Node.childNodes[I].nodeType = NODE_ATTRIBUTE)
or (Node.childNodes[I].nodeName = '
#text')
then
begin
Inc(I);
Continue;
end;
if I = 0
then
InsertFormattingNode(Node, Nesting + 1, I)
else
InsertFormattingNode(Node, 1, I, False);
Inc(I, 2);
InsertFormattingNode(Node, Nesting, I);
Inc(I);
end;
for I := 0
to Node.childNodes.length - 1
do
ProcessList(Node.childNodes[I]);
end;
begin
ProcessList(
XML.documentElement);
end;