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

Type converter for NodeList with size 1 to Node

    XMLWordPrintableJSON

Details

    • Patch Available
    • 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

            raulvk Raúl Kripalani
            raulvk Raúl Kripalani
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: