//判断某子结点是否存在,增加代码的可靠性
//if NodeIsExist(FNodes,
//'Children[2].Children[3].Children[11].Children[3].Children[1].Children[1].Children[1].Children[0]'
//) then
//Memo3.Lines.Add(
//FNodes.Children[2].Children[3].Children[11].Children[3].Children[1].Children[1].Children[1].Children[0].InnerText
// );
function NodeIsExist(Root:IHtmlElement;Childrens:string):Boolean ;
var aStringlist:tStringlist; i,aIndex:integer;
aNode:IHtmlElement; aStr:string;
begin
Result:= False;
aStringlist:=TStringList.Create;
aStringlist.Delimiter := '.';
aStringlist.DelimitedText := Childrens;
aNode:=Root;
for i := to aStringlist.Count- do begin
aStr:=Copy(aStringlist[i],,Length(aStringlist[i])-);
aIndex:= StrToIntDef(aStr,);
if aIndex>= aNode.ChildrenCount then begin
aStringlist.Free;
Exit;
end;
aNode:=aNode.Children[aIndex];
end;
aStringlist.Free;
Result:= true;
end;
//NodeIsExist的优化版,更高速,只处理最大结点0~99
function NodeIsExist(Root:IHtmlElement;Childrens:string):Boolean ;
VAR i:integer;
aNode:IHtmlElement;
begin
Result:= False;
aNode:=Root;
for i:= to Length(Childrens) do begin //aString[1]从1开始,而不是从零开始
if Childrens[i]=# then begin // ']'
if Childrens[i-]=# then begin // '['
if StrToIntDef(Copy(Childrens,i-,),)>= aNode.ChildrenCount then Exit; //一位数
aNode:=aNode.Children[StrToIntDef(Copy(Childrens,i-,),)];
end;
if Childrens[i-]=# then begin // '['
if StrToIntDef(Copy(Childrens,i-,),)>= aNode.ChildrenCount then Exit; //二位数
aNode:=aNode.Children[StrToIntDef(Copy(Childrens,i-,),)];
end;
end;
end;
Result:= true;
end;