Repository: incubator-groovy Updated Branches: refs/heads/GROOVY_2_4_X be38e773b -> 6da982557
Documentation: Correct some typos Project: http://git-wip-us.apache.org/repos/asf/incubator-groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-groovy/commit/6da98255 Tree: http://git-wip-us.apache.org/repos/asf/incubator-groovy/tree/6da98255 Diff: http://git-wip-us.apache.org/repos/asf/incubator-groovy/diff/6da98255 Branch: refs/heads/GROOVY_2_4_X Commit: 6da98255786aec19fd28e01da0f5b89a7d6dbe43 Parents: be38e77 Author: pascalschumacher <pascalschumac...@gmx.net> Authored: Tue Jun 2 22:15:20 2015 +0200 Committer: pascalschumacher <pascalschumac...@gmx.net> Committed: Tue Jun 2 22:16:29 2015 +0200 ---------------------------------------------------------------------- .../groovy-xml/src/spec/doc/xml-userguide.adoc | 18 +++++++++--------- .../src/spec/test/UserGuideXmlSlurperTest.groovy | 6 +++--- 2 files changed, 12 insertions(+), 12 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/6da98255/subprojects/groovy-xml/src/spec/doc/xml-userguide.adoc ---------------------------------------------------------------------- diff --git a/subprojects/groovy-xml/src/spec/doc/xml-userguide.adoc b/subprojects/groovy-xml/src/spec/doc/xml-userguide.adoc index 49ce386..75fc990 100644 --- a/subprojects/groovy-xml/src/spec/doc/xml-userguide.adoc +++ b/subprojects/groovy-xml/src/spec/doc/xml-userguide.adoc @@ -52,7 +52,7 @@ When to use one or the another? NOTE: There is a discussion at http://stackoverflow.com/questions/7558019/groovy-xmlslurper-vs-xmlparser[StackOverflow]. The -conclusions written here are based partially in this entry. +conclusions written here are based partially on this entry. * *If you want to transform an existing document to another* then `XmlSlurper` will be the choice @@ -198,15 +198,15 @@ the Both of them are equally valid. -=== Speed things up with breadthFirst and depthfirst +=== Speed things up with breadthFirst and depthFirst If you ever have used XPath you may have used expressions like * `//` : Look everywhere * `/following-sibling::othernode` : Look for a node "othernode" in the same level -More or less we have their counterparts in `Gpath` with the methods -`breadthFirst()` and `depthfirst()`. +More or less we have their counterparts in `GPath` with the methods +`breadthFirst()` and `depthFirst()`. The first example shows a simple use of `breadthFirst()`. The creators of this methods created a shorter syntax for it using the symbol `*`. @@ -214,7 +214,7 @@ this methods created a shorter syntax for it using the symbol `*`. [source,groovy] .breadthFirst() ---- -include::{rootProjectDir}/subprojects/groovy-xml/src/spec/test/UserGuideXmlSlurperTest.groovy[tags=testBreadFirst1,indent=0] +include::{rootProjectDir}/subprojects/groovy-xml/src/spec/test/UserGuideXmlSlurperTest.groovy[tags=testBreadthFirst1,indent=0] ---- This test searches for any node at the same level of the "books" node @@ -236,7 +236,7 @@ we going to be able to find that book? `depthFirst()` is the solution: include::{rootProjectDir}/subprojects/groovy-xml/src/spec/test/UserGuideXmlSlurperTest.groovy[tags=testDepthFirst1,indent=0] ---- -`depthfirst()` is the same as looking something *everywhere in the +`depthFirst()` is the same as looking something *everywhere in the tree from this point down*. In this case we've used the method `find(Closure cl)` to find just the first occurrence. @@ -249,7 +249,7 @@ include::{rootProjectDir}/subprojects/groovy-xml/src/spec/test/UserGuideXmlSlurp ---- It is worth mentioning again that there are some useful methods -converting a node's value to an integer,float...etc. Those methods +converting a node's value to an integer, float... etc. Those methods could be convenient when doing comparisons like this: [source,groovy] @@ -259,7 +259,7 @@ include::{rootProjectDir}/subprojects/groovy-xml/src/spec/test/UserGuideXmlSlurp ---- In this case the number 2 has been hardcoded but imagine that value -could have come from any other source (database...etc). +could have come from any other source (database... etc.). == Creating XML @@ -548,7 +548,7 @@ node itself (for instance to add this node to another XML). For that you can use `groovy.xml.XmlUtil` class. It has several static methods to serialize the xml fragment from several type of sources -(Node,GPathResult,String...) +(Node, GPathResult, String...) [source,groovy] .Getting a node as a string http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/6da98255/subprojects/groovy-xml/src/spec/test/UserGuideXmlSlurperTest.groovy ---------------------------------------------------------------------- diff --git a/subprojects/groovy-xml/src/spec/test/UserGuideXmlSlurperTest.groovy b/subprojects/groovy-xml/src/spec/test/UserGuideXmlSlurperTest.groovy index 3608d84..9d5901f 100644 --- a/subprojects/groovy-xml/src/spec/test/UserGuideXmlSlurperTest.groovy +++ b/subprojects/groovy-xml/src/spec/test/UserGuideXmlSlurperTest.groovy @@ -94,8 +94,8 @@ class UserGuideXmlSlurperTest extends GroovyTestCase { // end::testGettingAnAttributeText[] } - void testBreadFirst1() { - // tag::testBreadFirst1[] + void testBreadthFirst1() { + // tag::testBreadthFirst1[] def response = new XmlSlurper().parseText(books) def catcherInTheRye = response.value.books.'*'.find { node-> @@ -104,7 +104,7 @@ class UserGuideXmlSlurperTest extends GroovyTestCase { } assert catcherInTheRye.title.text() == 'Catcher in the Rye' - // end::testBreadFirst1[] + // end::testBreadthFirst1[] } void testDepthFirst1() {