Uploaded image for project: 'Camel'
  1. Camel
  2. CAMEL-5403

Type converter for NodeList with size 1 to Node

Attach filesAttach ScreenshotVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

    Details

    • Patch Info:
      Patch Available
    • Estimated Complexity:
      Unknown

      Description

      In many cases, Xerces will return transformation results as a NodeList of size 1 even though the XPath evaluation only yields one element during runtime.

      <transform>
         <xpath>/child::node()[local-name() = 'ABC']</xpath>
      </transform>
      

      (that XPath is capable of matching multiple elements - but let's assume only one is matched)

      When applying an XPath choice afterwards, it is easy to come across this error:

      java.lang.ClassCastException: org.apache.xml.dtm.ref.DTMNodeList cannot be cast to org.w3c.dom.Node
      	at org.apache.xpath.jaxp.XPathExpressionImpl.eval(XPathExpressionImpl.java:121)[:]
      	at org.apache.xpath.jaxp.XPathExpressionImpl.eval(XPathExpressionImpl.java:99)[:]
      	at org.apache.xpath.jaxp.XPathExpressionImpl.evaluate(XPathExpressionImpl.java:184)[:]
      	at org.apache.camel.builder.xml.XPathBuilder.doInEvaluateAs(XPathBuilder.java:676)[88:org.apache.camel.camel-core:2.8.0.fuse-03-06]
      	at org.apache.camel.builder.xml.XPathBuilder.evaluateAs(XPathBuilder.java:640)[88:org.apache.camel.camel-core:2.8.0.fuse-03-06]
      	at org.apache.camel.builder.xml.XPathBuilder.matches(XPathBuilder.java:132)[88:org.apache.camel.camel-core:2.8.0.fuse-03-06]
      	at org.apache.camel.processor.ChoiceProcessor.process(ChoiceProcessor.java:65)[88:org.apache.camel.camel-core:2.8.0.fuse-03-06]
      [...]
      

      To make the out-of-the-box experience smoother, I propose adding a little type converter that converts from NodeList => Node when the size of the former is 1.

        Attachments

          Activity

            People

            • Assignee:
              raulvk Raúl Kripalani
              Reporter:
              raulvk Raúl Kripalani

              Dates

              • Created:
                Updated:
                Resolved:

                Issue deployment