0

DOMNodeListオブジェクトで.getElementsByTagNameを使用するにはどうすればよいですか?好き:

procedure TForm1.selecionarClick(Sender: TObject);
var  DOMDocument: iXMLDOMDocument;
     DOMNodeList: iXMLDOMNodeList;
     DOMNode: iXMLDOMNode;
     DOMElement: iXMLDOMElement;
     i: Integer;
begin
      Memo.Text := '';
      with DOMDocument do
      begin
            DOMDocument := coDOMDocument.Create;
            DOMDocument.load( 'C:\Usuarios.xml' );
            DOMDocument.preserveWhiteSpace := false;
            DOMNodeList := DOMDocument.selectNodes( './/usuario[@codigo="'+codigo.Text+'"]/' );
            for i := 0 to DOMNodeList.length - 1 do
            begin

            end;
      end;
end;

私のXML構造:

<?xml version="1.0" encoding="utf-8"?>
<usuarios>
    <usuario codigo="1">
           <nome>Name Node</nome>
           <sobrenome>Last Name Node</sobrenome>
           <cidade>City Node</cidade>
           <estado>State Node</estado>
           <email>Mail Node</email>
    </usuario>
</usuarios>
4

2 に答える 2

2

GetElementsByTagNameは IXMLDOMNodeList のメンバーではなく、IXMLDOMDocumentのメンバーです。IXMLDOMNodeList で、タグ名で取得するには、次のタイプの構造を使用してループする必要があります。

for i := 0 to DOMNodeList.length - 1 do
begin
  DOMNode := DOMNodeList[i];
  if DOMNode.nodeName = 'aTagName' then
   DoStuff(DOMNode);
  // etc etc....
end;

HTH

于 2011-07-23T04:08:45.823 に答える