| career | drupal | java | mac | mysql | perl | scala | uml | unix  

Groovy example source code file (NamespaceNodeGPathTest.groovy)

This example Groovy source code file (NamespaceNodeGPathTest.groovy) is included in the "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Groovy tags/keywords

edam, edam, found, found, namespace, namespace, namespacenodegpathtest, node, purchase, purchase, testxmlsupport

The Groovy NamespaceNodeGPathTest.groovy source code

package groovy.xml

 * Test the use of GPath navigation with namespaces
class NamespaceNodeGPathTest extends TestXmlSupport {

    void testTree() {
        Node root = new XmlParser().parseText("""
<xsd:schema xmlns:xsd="">
  <xsd:annotation xsd:cheese="Edam">
     <xsd:documentation>Purchase order schema for

        Namespace xsd = new Namespace('', 'xsd')

        def children = root.children()

        def name =

        root.children().each {println "has a child with name ${} and content $it"}

        def foo = xsd.annotation
        println "qname url is $foo.namespaceURI"
        println "qname prefix is $foo.prefix"
        println "qname localPart is $foo.localPart"

        def a = root[xsd.annotation]
        println "Found results $a"

        assert a.size() == 1: " size is $a.size()"

        def aNode = a[0]
        def cheese = aNode.attributes()[xsd.cheese]
        assert cheese == "Edam"
        println "Found namespaced attribute $cheese"

        cheese = aNode.attribute(xsd.cheese)
        assert cheese == "Edam"
        println "Found namespaced attribute $cheese"

        def e = root[xsd.annotation][xsd.documentation]
        assert e.size() == 1: " size is $e.size()"
        assert e.text() == "Purchase order schema for"

        e = a[xsd.documentation]
        assert e.size() == 1: " size is $e.size()"
        assert e.text() == "Purchase order schema for"

Other Groovy examples (source code examples)

Here is a short list of links related to this Groovy NamespaceNodeGPathTest.groovy source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller


new blog posts


Copyright 1998-2021 Alvin Alexander,
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.