Menu

TreeInfo.selectId() to select element by ID efficiently

saxon-help
2016-06-25
2016-06-25
  • Marc Dzaebel

    Marc Dzaebel - 2016-06-25

    See https://saxonica.plan.io/boards/3/topics/6460

    Hi,

    in my Java program with Saxon 9-7, I need to find the element with an ID attribute (without prefix) set to a certain value. While there are slow XPath methods like "//*[@ID='" + refID + "']", or "id(...)" there is a selectID method on TreeInfo, that seems to be more efficient but it returns null.

    Input: <root> <node ID="1"/> </root>
    Program: nodeInfo.getTreeInfo().selectID("1", false); // returns null

    I know, there must be a DTD that defines the attribute as being of type ID and the parser must be capable. However, without having a DTD, is it possible to get the element efficiently and how?

    Thanks, Marc Dzaebel

     

    Last edit: Marc Dzaebel 2016-06-25
  • Michael Kay

    Michael Kay - 2016-06-25

    Please follow this discussion at https://saxonica.plan.io/boards/3/topics/6460