Menu

#8 Core functions

wont-fix
nobody
None
5
2017-06-23
2017-06-20
No

Hi,
I am testing the XPathWraper and have a problem by using core functions.

    private XPathWrapperFactory wrapperFactory = new XPathWrapperFactory()
            .bindNamespace("bpmn", "http://www.omg.org/spec/BPMN/20100524/MODEL")
            .bindNamespace("form", "http://www.bpsim.org/schemas/1.0");

     Document dom = ParseUtil.parse(new File("Model/Test3.bpmn"));

      XPathWrapper xpw = wrapperFactory.newXPath("../../../../../../../name()");
      result = xpw.evaluateAsString(dom);

and I get:
Exception in thread "main" net.sf.practicalxml.XmlException: unable to compile: ../../../../../../../name()

What is wrong? must I bind the core functions?

Christian

Discussion

  • Keith D Gregory

    Keith D Gregory - 2017-06-23

    This is actually a limitation of the JDK, and perhaps of the XPath 1.0 expression syntax (although I've been looking at the BNF to determine just how a LocationPath is a special case of an Expr, and am not finding anything clear -- I would have expected a LocationPath to be one of the PrimaryExpr forms, but it isn't).

    Regardless, it isn't an issue with binding. Here are some examples:

        Document dom = ParseUtil.parse("<root>"
                                     + "  <child>"
                                     + "    <grandchild>text</grandchild>"
                                     + "  </child>"
                                     + "</root>");
    
        XPathWrapper wrapper1 = new XPathWrapper("name(/root/child)");
        System.out.println(wrapper1.evaluateAsString(dom));
    
        // note that this second example selects only text, including whitespace
        XPathWrapper wrapper2 = new XPathWrapper("/root/*[name()='child']");
        System.out.println(wrapper2.evaluateAsString(dom));
    
     

    Last edit: Keith D Gregory 2017-06-23
  • Keith D Gregory

    Keith D Gregory - 2017-06-23
    • status: open --> wont-fix
     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.