function TNXXmlDocument.Content:
string;
var
ElementList: TStringList;
AttributeList: TStringList;
{ ExpandElements }
procedure ExpandElements(
const Indent:
string; Elements: TNXXmlElements);
var
Str:
String;
i, j: Integer;
begin
for i := 0
to Elements.Count - 1
do
begin
AttributeList.Clear;
for j := 0
to Elements[i].Attributes.Count - 1
do
AttributeList.Add(Elements[i].Attributes[j].
Name + '
="' + Elements[i].Attributes[j].Value + '
"');
if Elements[i].Elements.Count > 0
then
begin
ElementList.Add(Indent + '
<' + Trim(Elements[i].
Name + '
' + AttributeList.DelimitedText) + '
>');
ExpandElements(Indent + '
', Elements[i].Elements);
ElementList.Add(Indent + '
</' + Elements[i].
Name + '
>');
end
else
begin
Str := Trim(Elements[i].Content);
if Str <> '
'
then
ElementList.Add(Indent + '
<' + Trim(Elements[i].
Name + '
' + AttributeList.Text) + '
>' + Str + '
</' + Elements[i].
Name + '
>')
else
ElementList.Add(Indent + '
<' + Trim(Elements[i].
Name + '
' + AttributeList.Text) + '
/>');
end
end;
end;
begin
ElementList := TStringList.Create;
try
ElementList.Add('
<?xml version="1.0" encoding="utf-8" ?>');
AttributeList := TStringList.Create;
try
AttributeList.QuoteChar := #0;
AttributeList.Delimiter := '
';
ExpandElements('
', Elements);
Result := ElementList.Text;
finally
AttributeList.Free;
end;
finally
ElementList.Free;
end;
end;