You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by pa...@apache.org on 2015/06/02 21:27:54 UTC

incubator-groovy git commit: Documentation: Add DOMBuilder section

Repository: incubator-groovy
Updated Branches:
  refs/heads/GROOVY_2_4_X 8bddea8a8 -> 7c5c575a1


Documentation: Add DOMBuilder section


Project: http://git-wip-us.apache.org/repos/asf/incubator-groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-groovy/commit/7c5c575a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-groovy/tree/7c5c575a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-groovy/diff/7c5c575a

Branch: refs/heads/GROOVY_2_4_X
Commit: 7c5c575a185369533f2ccccaa8477d850d844746
Parents: 8bddea8
Author: pascalschumacher <pa...@gmx.net>
Authored: Tue Jun 2 21:10:28 2015 +0200
Committer: pascalschumacher <pa...@gmx.net>
Committed: Tue Jun 2 21:27:29 2015 +0200

----------------------------------------------------------------------
 .../doc/core-domain-specific-languages.adoc     |  4 +-
 .../groovy-xml/src/spec/doc/dom-builder.adoc    | 24 +++++++++
 .../src/spec/test/DOMBuilderTest.groovy         | 52 ++++++++++++++++++++
 3 files changed, 77 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/7c5c575a/src/spec/doc/core-domain-specific-languages.adoc
----------------------------------------------------------------------
diff --git a/src/spec/doc/core-domain-specific-languages.adoc b/src/spec/doc/core-domain-specific-languages.adoc
index 66c7072..d73b81c 100644
--- a/src/spec/doc/core-domain-specific-languages.adoc
+++ b/src/spec/doc/core-domain-specific-languages.adoc
@@ -1033,9 +1033,7 @@ include::{projectdir}/subprojects/groovy-xml/{specfolder}/sax-builder.adoc[level
 
 include::{projectdir}/subprojects/groovy-xml/{specfolder}/stax-builder.adoc[leveloffset=+3]
 
-==== DomBuilder
-
-(TBD)
+include::{projectdir}/subprojects/groovy-xml/{specfolder}/dom-builder.adoc[leveloffset=+3]
 
 ==== NodeBuilder
 

http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/7c5c575a/subprojects/groovy-xml/src/spec/doc/dom-builder.adoc
----------------------------------------------------------------------
diff --git a/subprojects/groovy-xml/src/spec/doc/dom-builder.adoc b/subprojects/groovy-xml/src/spec/doc/dom-builder.adoc
new file mode 100644
index 0000000..b2baa42
--- /dev/null
+++ b/subprojects/groovy-xml/src/spec/doc/dom-builder.adoc
@@ -0,0 +1,24 @@
+= DOMBuilder
+
+A builder for parsing HTML, XHTML and XML into a https://en.wikipedia.org/wiki/Document_Object_Model[W3C DOM] tree.
+
+For example this XML `String`:
+
+[source,groovy]
+----
+include::{rootProjectDir}/subprojects/groovy-xml/src/spec/test/DOMBuilderTest.groovy[tags=xml_string,indent=0]
+----
+
+Can be parsed into a DOM tree with a `DOMBuilder` like this:
+
+[source,groovy]
+----
+include::{rootProjectDir}/subprojects/groovy-xml/src/spec/test/DOMBuilderTest.groovy[tags=dom_builder_parse,indent=0]
+----
+
+And then processed further e.g. by using <<_domcategory,DOMCategory>>:
+
+[source,groovy]
+----
+include::{rootProjectDir}/subprojects/groovy-xml/src/spec/test/DOMBuilderTest.groovy[tags=dom_builder_process_result,indent=0]
+----
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/7c5c575a/subprojects/groovy-xml/src/spec/test/DOMBuilderTest.groovy
----------------------------------------------------------------------
diff --git a/subprojects/groovy-xml/src/spec/test/DOMBuilderTest.groovy b/subprojects/groovy-xml/src/spec/test/DOMBuilderTest.groovy
new file mode 100644
index 0000000..b1fb026
--- /dev/null
+++ b/subprojects/groovy-xml/src/spec/test/DOMBuilderTest.groovy
@@ -0,0 +1,52 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+class DOMBuilderTest extends GroovyTestCase {
+
+    void testDOMBuilderParseText() {
+        // tag::xml_string[]
+        String recordsXML = '''
+            <records>
+              <car name='HSV Maloo' make='Holden' year='2006'>
+                <country>Australia</country>
+                <record type='speed'>Production Pickup Truck with speed of 271kph</record>
+              </car>
+              <car name='P50' make='Peel' year='1962'>
+                <country>Isle of Man</country>
+                <record type='size'>Smallest Street-Legal Car at 99cm wide and 59 kg in weight</record>
+              </car>
+              <car name='Royale' make='Bugatti' year='1931'>
+                <country>France</country>
+                <record type='price'>Most Valuable Car at $15 million</record>
+              </car>
+            </records>'''
+        // end::xml_string[]
+        
+        // tag::dom_builder_parse[]
+        def reader = new StringReader(recordsXML)
+        def doc = groovy.xml.DOMBuilder.parse(reader)
+        // end::dom_builder_parse[]
+        
+        // tag::dom_builder_process_result[]
+        def records = doc.documentElement
+        use(groovy.xml.dom.DOMCategory) {
+            assert records.car.size() == 3
+        }
+        // end::dom_builder_process_result[]
+  }
+}