groovy-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pascalschumac...@apache.org
Subject incubator-groovy git commit: Documentation: Add DOMBuilder section
Date Tue, 02 Jun 2015 19:28:24 GMT
Repository: incubator-groovy
Updated Branches:
  refs/heads/master a34ed8b1b -> b0b4c1565


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/b0b4c156
Tree: http://git-wip-us.apache.org/repos/asf/incubator-groovy/tree/b0b4c156
Diff: http://git-wip-us.apache.org/repos/asf/incubator-groovy/diff/b0b4c156

Branch: refs/heads/master
Commit: b0b4c15653225bf60f667aeca05255fe70a1ab5e
Parents: a34ed8b
Author: pascalschumacher <pascalschumacher@gmx.net>
Authored: Tue Jun 2 21:10:28 2015 +0200
Committer: pascalschumacher <pascalschumacher@gmx.net>
Committed: Tue Jun 2 21:25:52 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/b0b4c156/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/b0b4c156/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/b0b4c156/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[]
+  }
+}


Mime
View raw message