Announcement Announcement Module
No announcement yet.
JaxenXPathTemplate is eating the tags Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • JaxenXPathTemplate is eating the tags

    I'm trying to find out why by XPath expressions that work in other tools are not working with the JaxenXPathTemplate.
    I created a simple test case:
      @Test public void testBlahBlahBlah()  {
        String str =
            "<soap-env:Envelope xmlns:soap-env=\"\" xmlns:SOAP-ENC=\"\" xmlns:xsd=\"\" xmlns:SOAP-ENV=\"\" xmlns:wsse=\"\" xmlns:xsi=\"\">" +
                     "   <soap-env:Header/>\n" +
            "   <soap-env:Body xmlns:soap-env=\"\">\n" +
            "      <soap-env:Fault>\n" +
            "         <faultcode>soap-env:Server</faultcode>\n" +
            "         <faultstring>Exception Code: 000. Executing Facade: Transferencias, Method: doSomething</faultstring>\n" +
            "         <faultactor>http://eric_estarda</faultactor>\n" +
            "         <detail>\n" +
            "            <prefixRigel0:Something xmlns:prefixRigel0=\"\">\n" +
            "               <kcMensaje>\n" +
            "                  <codigo>MD_0033</codigo>\n" +
            "                  <descripcion>THE CONTRACT MUST BE SPECIFIED</descripcion>\n" +
            "               </kcMensaje>\n" +
            "            </prefixRigel0:Something>\n" +
            "         </detail>\n" +
            "      </soap-env:Fault>\n" +
            "   </soap-env:Body>\n"+
        JaxenXPathTemplate xpathTemplate = new JaxenXPathTemplate();
         System.out.println("["+xpathTemplate.evaluateAsString( ".", new StringSource( str ) )+"]");
    What I get is this:
             Exception Code: 000. Executing Facade: Transferencias, Method: doSomething
                      THE CONTRACT MUST BE SPECIFIED
    It's no wonder that my XPath expressions are failing. All of the tags have been eaten. Why?

    I'm using
    revision.springframework = 3.1.2
    revision.spring-int = 2.1.3
    revision.spring-ws = 2.1.0

  • #2
    I found out the answer to my question.
    The root of my confusion was that I was not see in the same results when using the XPathTemplate rather than a XPath path builder to such as one at Toolz (
    I didn't realize that the '.' expression when evaluated by the tool was showing my the node, where as the XPathTemplate gave be exactly what I asked for which was a string.

    I stepped through the code with the JaxenXpathTemplate to see why the results look so odd, and it boils down to how the Jaxen DocumentNavigator builds the response string. I expect that Jaxp13XPathTemplate gives the same results for the same reason.
    Here's the Jaxen code that answered my question, and reminded me about the basics of XML handling:
         * Construct a node's string value recursively.
         * @param node the current node
         * @param buffer the buffer for building the text
         * @return the buffer passed as a parameter (for convenience)
        private StringBuffer getStringValue (Node node, StringBuffer buffer)
            if (isText(node)) {
            } else {
                NodeList children = node.getChildNodes();
                int length = children.getLength();
                for (int i = 0; i < length; i++) {
                    getStringValue(children.item(i), buffer);
            return buffer;