From 394efd2a2a14959e5d4ecfc8e3bd2a8828f6c21d Mon Sep 17 00:00:00 2001 From: Oleg Zhurakousky Date: Wed, 15 Sep 2010 22:43:41 -0400 Subject: [PATCH] INT-1438, added XPath transformer documentation --- .../integration/xml/XmlPayloadConverter.java | 2 +- src/docbkx/xml.xml | 100 +++++++++++++++++- 2 files changed, 100 insertions(+), 2 deletions(-) diff --git a/spring-integration-xml/src/main/java/org/springframework/integration/xml/XmlPayloadConverter.java b/spring-integration-xml/src/main/java/org/springframework/integration/xml/XmlPayloadConverter.java index d9c2cd74b1..0a92c04b0e 100644 --- a/spring-integration-xml/src/main/java/org/springframework/integration/xml/XmlPayloadConverter.java +++ b/spring-integration-xml/src/main/java/org/springframework/integration/xml/XmlPayloadConverter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2010 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/docbkx/xml.xml b/src/docbkx/xml.xml index d260ae908e..cf75252e3d 100644 --- a/src/docbkx/xml.xml +++ b/src/docbkx/xml.xml @@ -1,7 +1,7 @@ - Dealing with XML Payloads + XML Support - Dealing with XML Payloads
Introduction @@ -328,6 +328,104 @@ ]]>
+
+ Transforming xml messages using XPath + + When it comes to message transformation XPath is a great way to transform Messages that have XML + payloads by defining XPath transformers via xpath-transformer element. + + + Simple XPath transformation + + + Let's look at the following transformer configuration: + ]]> + + . . . and Message + message = + MessageBuilder.withPayload("").build();]]> + After sending this message to the 'inputChannel' the XPath transformer configured above will transform + this XML Message to a simple Message with payload of 'John Doe' all based on + the simple XPath Expression specified in the xpath-expression attribute. + + + XPath also has capability to perform simple conversion of extracted elements + to a desired type. Valid return types are defined in XPathConstants and follows + the conversion rules specified by the XPath. + + + The following constants are defined by the XPathConstants: BOOLEAN, DOM_OBJECT_MODEL, NODE, NODESET, NUMBER, STRING + + + You can configure the desired type by simply using evaluation-type + attribute of the xpath-transformer element. + + + +]]> + + + Node Mappers + + + If you need to provide custom mapping for the node extracted by the XPath expression simply provide a reference to the + implementation of the org.springframework.xml.xpath.NodeMapper - an interface used by + XPathOperations implementations for mapping Node objects on a per-node basis. To provide a + reference to a NodeMapper simply use node-mapper attribute: + +]]> +. . . and Sample NodeMapper implementation: + + + + XML Payload Converter + + + You can also use implementation of the org.springframework.integration.xml.XmlPayloadConverter to + provide more granular transformation: + +]]> +. . . and Sample XmlPayloadConverter implementation: +"))); + } + catch (Exception e) { + throw new IllegalStateException(e); + } + } + // + public Document convertToDocument(Object object) { + throw new UnsupportedOperationException(); + } +}]]> + + + Combination of SpEL and XPath expressions + + + You can also combine Spring Expression Language (SpEL) expressions with XPath expression and configure + them using expression attribute: + ]]> + In the above case the overall result of the expression will be the result of the XPathe expression multiplied by 2. + +
+
XPath components namespace support