Finding elements with XPath in Delphi

后端 未结 3 372
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-16 11:12

I am trying to find an element in an XML document in Delphi. I have this code, but it always says 0 elements in the log:

function TForm1.KannaSidu: Boolean;
         


        
3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-16 12:07

    IXMLDOMDocument.Load() does not raise an exception if something goes wrong with your file or with its content. Try the following to be sure there is nothing bad with it:

    ...
    Doc.load(Filename);
    if Doc.parseError.errorCode <> 0 then
      ShowMessage('Error : ' + + Doc.parseError.reason) 
    else
      ShowMessage('No problem so far !');
    ...
    

    I suck at XPath but maybe if html is your root node you don't need to include it in your query string, so try the following :

    List:=Doc.selectNodes('//html/head');
    

    or

    List:=Doc.selectNodes('//head');
    

提交回复
热议问题