function ErgodicXML(ANode: IXMLNode): string;
var
  i: Integer;
  Name, Value: 
string;
begin
  Result :
= '';
  
if ANode.NodeType = ntText then exit;    { 如果是ntText节点则返回 }

  Result :
= '<' + ANode.NodeName;            { 节点名称 }
  
for i := 0 to ANode.AttributeNodes.Count - 1 do    { 节点属性 }
  
begin
    Name :
= ANode.AttributeNodes[i].NodeName;
    Value :
= ANode.AttributeNodes[i].NodeValue;
    Result :
= Result + ' ' + Name + '=' + AnsiQuotedStr(Value, '"');
  
end;
  Result :
= Result + '>';

  
if ANode.IsTextElement then                    { 如果有Text信息就提取它 }
    Result :
= Result + ANode.Text
  
else Result := Result + sLineBreak;
  
for i := 0 to ANode.ChildNodes.Count - 1 do
    Result :
= Result + ErgodicXML(ANode.ChildNodes[i]);     { 递归调用 }

  Result :
= Result + '</' + ANode.NodeName + '>' + sLineBreak;
end;
posted on 2009-01-15 18:05  云中君  阅读(699)  评论(0编辑  收藏  举报