Return-Path: X-Original-To: apmail-camel-users-archive@www.apache.org Delivered-To: apmail-camel-users-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id BC70141FB for ; Sat, 21 May 2011 11:59:41 +0000 (UTC) Received: (qmail 5331 invoked by uid 500); 21 May 2011 11:59:41 -0000 Delivered-To: apmail-camel-users-archive@camel.apache.org Received: (qmail 5294 invoked by uid 500); 21 May 2011 11:59:41 -0000 Mailing-List: contact users-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@camel.apache.org Delivered-To: mailing list users@camel.apache.org Received: (qmail 5286 invoked by uid 99); 21 May 2011 11:59:41 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 21 May 2011 11:59:41 +0000 X-ASF-Spam-Status: No, hits=-0.7 required=5.0 tests=FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,RFC_ABUSE_POST,SPF_PASS,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of claus.ibsen@gmail.com designates 74.125.83.173 as permitted sender) Received: from [74.125.83.173] (HELO mail-pv0-f173.google.com) (74.125.83.173) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 21 May 2011 11:59:35 +0000 Received: by pvg3 with SMTP id 3so2393565pvg.32 for ; Sat, 21 May 2011 04:59:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:from:date :message-id:subject:to:content-type:content-transfer-encoding; bh=Rgecvvxz1qvkL7rj2k98vhpJB+TY1sXRro8ELlCOAQ8=; b=jykGYsjWiGXlJZ55w/FCgGlVh38QjcHfhflik2BNWVE4X9l0/jPxBGhv3vC1JzT06g sg+khAYPkEIHcAz8nN+YIfjQkjKzEprEjiEy+nEnUfT4zWPL8wm7kmcb5L7HWqPTz4hR C01RwWB6JKgb+Hu8GK/lLkXd6BSHkACgIMxXs= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type:content-transfer-encoding; b=Hg0XEvRkdgiQvk25/ybtYHmDz1Sb32yrDg6OYUx7oaFpVYTv9iG+VQ0CDqa/472ZH4 ZLiwI7i+15x7HonaloCcnWfV4FttDP/TPM3p2UsDz5v0VblAE5O9nZwab64RDNqV3opD 7FsmVJfUTiNXRzlngH1jz6B/+5K6WkRxPX5/s= Received: by 10.68.4.194 with SMTP id m2mr757633pbm.228.1305979154032; Sat, 21 May 2011 04:59:14 -0700 (PDT) MIME-Version: 1.0 Received: by 10.68.55.33 with HTTP; Sat, 21 May 2011 04:58:54 -0700 (PDT) In-Reply-To: References: <1305837612335-4410859.post@n5.nabble.com> <20110520051057.1B5623AD@athena.apache.org> From: Claus Ibsen Date: Sat, 21 May 2011 13:58:54 +0200 Message-ID: Subject: Re: an un-easy way to use camel-xpath in:header() function To: users@camel.apache.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Checked: Checked by ClamAV on apache.org 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 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 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 wrote= : >> >>> Have you looked at the Validation component? >>> http://camel.apache.org/validation.html >>> >>> >>> On Fri, May 20, 2011 at 7:10 AM, ext2 wrote: >>> >>>> Using camel's in:header() xpath function, =A0we can deal with =A0xml s= tored in >>>> message header very easy; for example: >>>> =A0 =A0 =A0 =A0 >>>> >>>> =A0in:header('bookstore')/child::book[price<100] >>>> =A0 =A0 =A0 =A0 >>>> >>>> The setHeader could retrieve all cheaper books(price less than 100) fr= om a >>>> bookstore xml (which already stored in message header('bookstore') >>>> >>>> But in camel, things are not always so easy. The user must make sure i= nput >>>> 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 coul= d be >>>> convert to xml. If the body cannot, then using a null instead of origi= nal >>>> message body to do XPathExpression.evaluate; >>>> >>>> >>>> >>> >> > --=20 Claus Ibsen ----------------- FuseSource Email: cibsen@fusesource.com 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/