[fpc-pascal] fcl-xml

Daniel Gaspary dgaspary at gmail.com
Tue Mar 12 15:23:31 CET 2013


On Tue, Mar 12, 2013 at 11:17 AM, Daniel Gaspary <dgaspary at gmail.com> wrote:
> Using Xpath I believe would be something like this:

I was missing an If:

function ElementById(id: string; doc: TXMLDocument): TDOMElement;
var
   v: TXPathVariable;
begin
     result:=nil;
     try
        v:=EvaluateXPathExpression('//*[@id=' + QuotedStr(id)+']',
             doc.DocumentElement);

        with v.AsNodeSet do
        begin
             if Count>0
             then
                 result:=TDOMElement(Items[0]);
        end;
     finally
            FreeAndNil(v);
     end;
end;



More information about the fpc-pascal mailing list