Если вы сначала включите эти 3 общие библиотечные процедуры ....
uses XMLDoc, XMLIntf, xmldom;
function CreateXMLDocument( var Owner1: TComponent): TXMLDocument;
begin
Owner1 := TComponent.Create( nil);
result := TXMLDocument.Create( Owner1);
result.Options := [doNodeAutoCreate, doNodeAutoIndent, doAttrNull,
doAutoPrefix, doNamespaceDecl];
result.DOMVendor := GetDOMVendor( 'MSXML');
end;
function XPATHSelect( const FocusNode: IXMLNode; const sXPath: string): TArray<IXMLNode>;
var
DomNodeSelect: IDomNodeSelect;
DOMNode : IDomNode;
DocAccess : IXmlDocumentAccess;
Doc : TXmlDocument;
DOMNodes : IDOMNodeList;
iDOMNode : integer;
begin
SetLength( result, 0);
if assigned( FocusNode) and
Supports( FocusNode.DOMNode, IDomNodeSelect, DomNodeSelect) then
DOMNodes := DomNodeSelect.SelectNodes( sXPath);
if not assigned( DOMNodes) then exit;
SetLength( result, DOMNodes.Length);
for iDOMNode := 0 to DOMNodes.Length - 1 do
begin
Doc := nil;
DOMNode := DOMNodes.item[iDOMNode];
if Supports( DOMNode, IXmlDocumentAccess, DocAccess) then
Doc := DocAccess.DocumentObject;
result[ iDOMNode] := TXmlNode.Create( DOMNode, nil, Doc) as IXMLNode;
end
end;
function XPATHSelectFirst( const FocusNode: IXMLNode; const sXPath: string; var SelectedNode: IXMLNode): boolean;
var
DomNodeSelect: IDomNodeSelect;
DOMNode : IDomNode;
DocAccess : IXmlDocumentAccess;
Doc : TXmlDocument;
begin
SelectedNode := nil;
if assigned( FocusNode) and
Supports( FocusNode.DOMNode, IDomNodeSelect, DomNodeSelect) then
DOMNode := DomNodeSelect.selectNode( sXPath);
if assigned( DOMNode) and
Supports( DOMNode.OwnerDocument, IXmlDocumentAccess, DocAccess) then
Doc := DocAccess.DocumentObject;
if Assigned( DOMNode) then
SelectedNode := TXmlNode.Create( DOMNode, nil, Doc);
result := assigned( SelectedNode)
end;
Тогда гораздо более удачным решением будет ...
procedure TForm2.btn1Click(Sender: TObject);
const
DocumentSource = 'http://softez.pp.ua/gg.xml';
var
Doc: IXMLDocument;
DocOwner: TComponent;
RowNode, PhraseNode, UrlNode: IXMLNode;
procedure PutLn( const LineFmt: string; const Args: array of const);
begin
memo2.Lines.Add( Format( LineFmt, Args))
end;
begin
memo2.Clear;
Doc := CreateXMLDocument( DocOwner);
Doc.LoadFromFile( DocumentSource);
for RowNode in XPATHSelect( Doc.DocumentElement, '//row[phrase]') do
begin
if not XPATHSelectFirst( RowNode, 'phrase', PhraseNode) then continue;
PutLn( 'phrase=%s', [PhraseNode.NodeValue]);
for UrlNode in XPATHSelect( RowNode, 'search_engines/search_engine/se_url') do
PutLn( 'url=%s', [UrlNode.NodeValue]);
PutLn('--------------',[])
end;
DocOwner.Free;
end;
Это было проверено на Delphi 2010 и работает удовольствие.