Project: mule
Issue MULE-7465: XPATH Expression Language - Dom4J creates separate text-nodes
h2. Overview *1 - XML Document* {code:xml}	email	prachurya.barua@bt.com	Voice Circuit Details	hi {code} *2 - Message property set using an xpath expression* {code:xml} {code} *3 - Other properties set using MEL xpath function* {code:xml} {code} *4 - An array is assigned to the toAddressesOldWay property* SESSION scoped properties: subjectXPath=Voice Circuit Details toAddress=prachurya.barua@bt.com *{color:red}toAddressesOldWay=[prachu, rya.barua@bt.com]{color}* toAddressesXPath=prachurya.barua@bt.com h2. Explanation The method *characters* of class *org.dom4j.io.SAXContentHandler* can generate multiple text nodes if *mergeAdjacentText* property is set to false. An excellent explanation of the reasons of why this happen can be found [here|http://www.mail-archive.com/dom4j-user@lists.sourceforge.net/msg02690.html]. The effect of this problem is that certain xpath expression, most notably related to the use of the text() selector, can return an array of text nodes instead of a single text node. This can lead to incomplete text values or wrong comparisons. This problem was discovered while dealing with a message properties transformer, where new message properties are added using xpath expressions to retrieve some values from an XML payload (this payload is converted to a DOM Document by means of the XmlToDomDocument transformer). This problem also affect the Expression Filter when using an xpath evaluator (uncomment the expression-filter element in the attached Mule configuration file to see it in action). References to the Dom4j issue are reported in [Dom4j Case #117 - Problem with XPath and retrieving text |http://sourceforge.net/p/dom4j/bugs/117/?page=0] Please find attached the Custom transformer that shows how to set the MergeAdjacentText property, the source code of xerces 2.9.1 and the xerces' binaries built with debugging information enabled (the binaries commonly distributed by Apache Xerces project have the debugging info stripped out). For the CustomXmlToDomDocument transformer to work, uncomment the custom-transformer element in the attached Mule configuration file. Please take notice that the return class must be set to org.dom4j.Document. h2. Workarounds *1 - Use any of the following equivalent xpath expressions:* {code} #[xpath:/child::sswa2smtp/child::toAddress[text()]] #[xpath:/sswa2smtp/toAddress[text()]] #[xpath:/child::*/toAddress[text()]] #[xpath:/*/toAddress[text()]] #[xpath:/descendant::toAddress[text()]] #[xpath:string(/*/toAddress)]" #[xpath://toAddress] {code} *2 - Use the attached CustomXmlToDomDocument transformer:* {code:xml} {code}
Story points: 3