Einzelnen Beitrag anzeigen

xaromz

Registriert seit: 18. Mär 2005
1.682 Beiträge
 
Delphi 2006 Enterprise
 
#4

Re: IXMLDOMDocument formatieren

  Alt 16. Jul 2009, 22:02
Hallo,

ich habe da eine eigene Funktion:
Delphi-Quellcode:
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;
Gruß
xaromz
I am a leaf on the wind - watch how I soar
  Mit Zitat antworten Zitat