1

I want to validate my xpath paramaters

This is my xml

<parent>
  <a>
    <c>name1</c>
  </a>
    <b>name2</b>
</parent>

Following is my java code

    String xmlPayload="<parent><a><c>name1</c></a><b>name2</b></parent>";
    OMElement xmlOMOBject= AXIOMUtil.stringToOM(xmlPayload);
    String key1="//a";
    String key2="/c";
    SimpleVariableContext svc=new SimpleVariableContext();
    svc.setVariableValue("part1",key1);
    svc.setVariableValue("part2",key2);

    AXIOMXPath axiomxPath = new AXIOMXPath("$part1$part2");
    axiomxPath.setVariableContext(svc);
    System.out.println(axiomxPath.selectSingleNode(xmlOMOBject));

but above code gives me an error.

Exception in thread "main" org.jaxen.XPathSyntaxException: Unexpected '$'

How to set context variables and evaluate the axiom xpath correctly.

user2694734
  • 401
  • 2
  • 7
  • 14

1 Answers1

0

$part1$part2 is not a valid XPath expression. concat($part1, $part2) would be valid, but it would simply evaluate to the string //a/c and would not evaluate //a/c as an XPath expression. I guess you want something like the evaluate function in EXSLT (and use dyn:evaluate(concat($part1, $part2))), but I'm not sure that Jaxen supports this function and this would still have the same effect as constructing the AXIOMXPath as follows:

AXIOMXPath axiomxPath = new AXIOMXPath(key1 + key2);
Andreas Veithen
  • 8,868
  • 3
  • 25
  • 28