求懂Delphi的帮忙把这段代码翻译成C++builder,谢谢
function ReadXml(node: IXMLNode): string;
var
nodeList,attrList: IXMLNodeList;
str,strName,strValue: string;
i: Integer;
begin
Result := '';
if not node.HasChildNodes then Exit;
attrList := node.AttributeNodes; {根节点的属性列表}
nodeList := node.ChildNodes; {根节点下的子节点列表}
str := '<' + node.NodeName;
{先读取属性}
for i := 0 to attrList.Count - 1 do
begin
strName := attrList[i].NodeName;
strValue := attrList[i].NodeValue;
str := str + ' ' + strName + '=' + AnsiQuotedStr(strValue, '"');
end;
str := str + '>' + sLineBreak; {sLineBreak 是常量, 相当于 #13#10}
{读取子节点}
for i := 0 to nodeList.Count - 1 do
begin
strName := nodeList[i].NodeName;
if nodeList[i].IsTextElement then
begin
strValue := nodeList[i].NodeValue;
str := str + '<' + strName + '>' + strValue + '</' + strName + '>' + sLineBreak;
end else if nodeList[i].HasChildNodes then
begin
str := str + ReadXml(nodeList[i]); {这是最关键的递归调用}
str := str + '</' + strName + '>' + sLineBreak; {封口}
end;
end;
str := str + '</' + node.NodeName + '>'; {封口}
Result := str;
end;
[解决办法]
#include "XMLIntf.hpp"
String ReadXml(_di_IXMLNode node)
{
_di_IXMLNodeList nodeList, attrList;
String str, strName, strValue;
int i;
if (!node->HasChildNodes) return EmptyStr;
attrList = node->AttributeNodes;
nodeList = node->ChildNodes;
str = "<" + node->NodeName;
for (i = 0; i < attrList->Count - 1; i++)
{
strName = attrList->Nodes[i]->NodeName;
strValue = attrList->Nodes[i]->NodeValue;
str = str + " " + sLineBreak + "=" + AnsiQuotedStr(strValue, '"');
}
str = str + ">" + sLineBreak;
for (i = 0; i < nodeList->Count - 1; i++)
{
strName = nodeList->Nodes[i]->NodeName;
if (nodeList->Nodes[i]->IsTextElement)
{
strValue = nodeList->Nodes[i]->NodeValue;
str = str + "<" + strName + ">" + strValue + "</ + strName + >" + sLineBreak;
}
else if (nodeList->Nodes[i]->HasChildNodes)
{
str = str + ReadXml(nodeList->Nodes[i]);
str = str + "</" + strName + ">" + sLineBreak;
}
}
str = str + "</" + node->NodeName + ">";
return str;
}