Hi, Claus: Yes you are right. The use case(header xml) isn't so widespread as the use-case( body xml)
When we find the body is not xml(it's very easy to check), how about to give the user another chance to deal with header using in:header function()? If so, we could extend the use-case for xpath expression, we could use it to deal with not only body xml , but also header xml. (Even we can deal with no-xml data, just like simple language does. (this is a side effect)) Anyway, this is just a suggestion. If you agree so, I could raise a issue and give a simple patch for it; > -----original ----- >sender: Claus Ibsen [mailto:[email protected]] > date: 2011/5/21 19:59 > Receiver: [email protected] > Subject: Re: an un-easy way to use camel-xpath in:header() function > > Hi > > You can use a POJO to set the header using xpath. > The xpath builder was designed to work on the message body. > > I wonder if your use case is widespread used, so its okay to alter the > code to support the use case? > > > On Fri, May 20, 2011 at 11:23 AM, tobeand <[email protected]> wrote: > > I guess the XPath language of Camel has one limitation. That is the > > body of input message must be a valid XML or null. > > > > In this problem, user want use XPath to process a xml in message > > header, but the message body is a plain text (not valid XML), and an > > exception occurs in parsing the content to DOM. > > > > After reading source code, we found that the > > XPathBuilder.doInEvaluateAs() method try to extract the document from > > the input message, and pass the document to XPathExpression.evaluate() > > method. The XPathBuilder.getDocument() method creates an InputSource > > for the text body and then the XPathExpression.evaluate() method > > creates a DocumentBuilder to parse the InputSource. > > > > > > > > On Fri, May 20, 2011 at 2:24 PM, Taariq Levack <[email protected]> wrote: > >> Also if null or an empty xml is valid in some situations, then a content > >> based router in front of this should do niely. > >> > >> On Fri, May 20, 2011 at 8:18 AM, Taariq Levack <[email protected]> wrote: > >> > >>> Have you looked at the Validation component? > >>> http://camel.apache.org/validation.html > >>> > >>> > >>> On Fri, May 20, 2011 at 7:10 AM, ext2 <[email protected]> wrote: > >>> > >>>> Using camel's in:header() xpath function, we can deal with xml stored > in > >>>> message header very easy; for example: > >>>> <setHeader name="cheaperBooks"> > >>>> > >>>> <xpath>in:header('bookstore')/child::book[price<100]</xpath> > >>>> </setHeader> > >>>> > >>>> The setHeader could retrieve all cheaper books(price less than 100) from > a > >>>> bookstore xml (which already stored in message header('bookstore') > >>>> > >>>> But in camel, things are not always so easy. The user must make sure input > >>>> message's body must be a valid XML or null(although the body's content > may > >>>> have nothing to do with the bookstore xml). Otherwise the above xapth > >>>> express will failed; > >>>> > >>>> Suggestion(Maybe): > >>>> > >>>> Camel's XPath expression should check if the input body's content could > be > >>>> convert to xml. If the body cannot, then using a null instead of original > >>>> message body to do XPathExpression.evaluate; > >>>> > >>>> > >>>> > >>> > >> > > > > > > -- > Claus Ibsen > ----------------- > FuseSource > Email: [email protected] > Web: http://fusesource.com > CamelOne 2011: http://fusesource.com/camelone2011/ > Twitter: davsclaus, fusenews > Blog: http://davsclaus.blogspot.com/ > Author of Camel in Action: http://www.manning.com/ibsen/
