DOMElement in Delphi

后端 未结 2 619
野性不改
野性不改 2021-01-29 01:35

how i can use .getElementsByTagName in DOMNodeList Object ? Like:

procedure TForm1.selecionarClick(Sender: TObject);
var  DOMDocument: iXMLDOMDocument;
     DOM         


        
相关标签:
2条回答
  • 2021-01-29 01:36

    GetElementsByTagName is not a member of IXMLDOMNodeList, but of IXMLDOMDocument. On IXMLDOMNodeList, to grab by tag name you must loop using this type of construct:

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

    HTH

    0 讨论(0)
  • 2021-01-29 01:44

    IDOMElement supports getElementsByTagName which returns an IDOMNodeList. IDOMElement is a "subclass" of IDOMNode.

    var
     DOMNode: IDOMNode;
     DOMElement: IDOMElement;
    begin
      if Node.DOMNode.nodeType <> ELEMENT_NODE then
        exit;
    
      // Obtain IDOMElement interface
      DOMElement := (DOMNode as IDOMElement);
      // Fetch node list
      DOMNodeList := DOMElement.getElementsByTagName('search text');
    
      // Do whatever with the list....
    end;
    

    Hope that helps. :)

    0 讨论(0)
提交回复
热议问题