From a84ed043c5df638f8e08c256f63110144371040f Mon Sep 17 00:00:00 2001 From: Arjen Poutsma Date: Fri, 18 May 2007 10:58:40 +0000 Subject: [PATCH] Docs, docs, docs. --- src/docbkx/common.xml | 125 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 125 insertions(+) diff --git a/src/docbkx/common.xml b/src/docbkx/common.xml index b7d56e54..c6615772 100644 --- a/src/docbkx/common.xml +++ b/src/docbkx/common.xml @@ -155,4 +155,129 @@ +
+ Handling XML With XPath + + One of the best ways to handle XML is to use XPath. Quoting , item 35: +
+ + XPath is a fourth generation declarative language that allows you to specify which nodes you want to + process without specifying exactly how the processor is supposed to navigate to those nodes. XPath's + data model is very well designed to support exactly what almost all developers want from XML. For + instance, it merges all adjacent text including that in CDATA sections, allows values to be + calculated that skip over comments and processing instructions` and include text from child and + descendant elements, and requires all external entity references to be resolved. In practice, XPath + expressions tend to be much more robust against unexpected but perhaps insignificant changes in the + input document. + + Elliotte Rusty Harold +
+
+ + Spring Web Services has two ways to use XPath within your application: the faster + XPathExpression or the more flexible XPathTemplate. + +
+ <interfacename>XPathExpression</interfacename> + + The XPathExpression is an abstraction over a compiled XPath expressions, + such as the Java 5 javax.xml.xpath.XPathExpression, or the Jaxen + XPath class. + To construct an expression in an application context, there is the + XPathExpressionFactoryBean. Here is an example which uses this factory bean: + + + + + + + + + + + +]]> + + The expression above does not use namespaces, but we could set those using the + namespaces property of the factory bean. The expression can be used in the code + as follows: + + + + For a more flexible approach, you can use a NodeMapper, which is similar + to the RowMapper in Spring's JDBC support. The following + example shows how we can use it: + + + + Similar to mapping rows in Spring JDBC's RowMapper, each result node is + mapped using an anonymous inner class. In this case, we create a Contact object, + which we use later on. + +
+
+ <classname>XPathTemplate</classname> + + The XPathExpression only allows you to evaluate a single, pre-compiled + expression. A more flexible, though slower, alternative is the XpathTemplate. + This class follows the common template pattern used throughout Spring (JdbcTemplate, JmsTemplate, etc.). + Here is an example: + + + + Of course, the template could have been injected with a constructor argument or a setter. + +
+
\ No newline at end of file