Skip to content

Feature request: support xpath functions like count #66

Closed
@MariePreusse

Description

@MariePreusse

I have a project where I need to use functions defined from xpath 1.0 like count and strings. Here is the definition of count:

Function: number count(node-set)

The count function returns the number of nodes in the argument node-set.

when running with xmllint e.g. I can enter on this playlist.xml (http://grantm.github.io/perl-libxml-by-example/_static/xpath-sandbox/xpath-sandbox.html)

xmllint --xpath "count(//person)" playlist.xml

and I get the number 18 as a result.

When using libxml++ I get the error message from nodes/node.cc:88 Only nodeset result types are supported.


  auto result = xmlXPathEval((const xmlChar*)xpath.c_str(), ctxt);
  if (!result)
  {
    xmlXPathFreeContext(ctxt);
    throw xmlpp::exception("Invalid XPath: " + xpath);
  }

  if (result->type != XPATH_NODESET)
  {
    xmlXPathFreeObject(result);
    xmlXPathFreeContext(ctxt);
    throw xmlpp::internal_error("Only nodeset result types are supported.");

Is there a way to use functions that have a result type that is not an xpath nodeset?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions