Menu

OXmlPDOM Fail on missing XPath node

Anonymous
2014-08-08
2014-08-20
  • Anonymous

    Anonymous - 2014-08-08

    First of all, great parser :) But i have a problem in Delphi XE6...
    This is my code...

    XmlDoc: IXMLDocument;
    GameNodes: IXMLNodeList;
    GameNode: PXMLNode;

    XmlDoc := OXmlPDOM.CreateXMLDoc;
    XmlStream := TMemoryStream.Create;
    SourceURL := ....;
    try
    IdHTTP1.Get(SourceUrl, XmlStream);
    XmlStream.Position := 0;
    XmlDoc.LoadFromStream(XmlStream);
    XmlDoc.DocumentElement.SelectNodes('...', GameNodes, 0);
    except
    on E: Exception do begin
    ..........
    Exit;
    end;
    end;

    for n := 0 to GameNodes.Count - 1 do begin
    GameNode := GameNodes.Nodes[n];
    Game := GameNode.Attributes['g'];
    L := GameNode.ParentNode.Attributes['l']; // go up
    Z := GameNode.SelectNode('z').NodeValue; // go down
    end;

    And if there are all attributes and nodes in xml that i'm searching - all is working fine, really nice, but let's say that node for z is missing, then i get this error:

    Access violation at address 006AAB1A in module .... Read Of address 00000000.

    In debbuger i get error on this line:
    xXPaths := TXMLXPathList.Create(TXMLXPathDOMAdapter.Create(OwnerDocument));

    Can someone pls help? I've tried few others parsers, but this one is really cool, just have to make it work :0...

     

    Last edit: Anonymous 2014-08-08
  • Ondrej Pokorny

    Ondrej Pokorny - 2014-08-20

    SelectNode('z') returns NIL if the 'z' node does not exist. Of course "SelectNode('z').NodeValue" throws an access violation then.

    Please read the documentation in the sources (= comments at the declaration of the functions/properties).

     

Anonymous
Anonymous

Add attachments
Cancel