gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[libeufin] branch master updated: implementing recursive definition of e


From: gnunet
Subject: [libeufin] branch master updated: implementing recursive definition of elements
Date: Sat, 07 Dec 2019 00:45:46 +0100

This is an automated email from the git hooks/post-receive script.

marcello pushed a commit to branch master
in repository libeufin.

The following commit(s) were added to refs/heads/master by this push:
     new e6cc1fc  implementing recursive definition of elements
e6cc1fc is described below

commit e6cc1fc96cd2b431f58abc735cb04f01e9123f8e
Author: Marcello Stanisci <address@hidden>
AuthorDate: Sat Dec 7 00:44:59 2019 +0100

    implementing recursive definition of elements
---
 .../kotlin/tech/libeufin/sandbox/XmlCombinators.kt | 22 +++++++++++++++++++---
 sandbox/src/test/kotlin/XmlCombinatorsTest.kt      |  9 ++++++++-
 2 files changed, 27 insertions(+), 4 deletions(-)

diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/XmlCombinators.kt 
b/sandbox/src/main/kotlin/tech/libeufin/sandbox/XmlCombinators.kt
index 054e17e..26fc940 100644
--- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/XmlCombinators.kt
+++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/XmlCombinators.kt
@@ -1,15 +1,31 @@
 package tech.libeufin.sandbox
 
 import com.sun.xml.txw2.output.IndentingXMLStreamWriter
+import org.jetbrains.exposed.sql.Op
 import java.io.StringWriter
+import java.util.*
 import javax.xml.stream.XMLOutputFactory
 import javax.xml.stream.XMLStreamWriter
 
 class XmlElementBuilder(val w: XMLStreamWriter) {
-    fun element(name: String, f: XmlElementBuilder.() -> Unit = {}) {
-        w.writeStartElement(name)
-        f(this)
+
+    fun element(path: MutableList<String>, f: XmlElementBuilder.() -> Unit = 
{}) {
+
+        if (path.isEmpty()) {
+            f(this)
+            return
+        }
+
+        w.writeStartElement(path.removeAt(0))
+        this.element(path, f)
         w.writeEndElement()
+
+    }
+
+    fun element(path: String, f: XmlElementBuilder.() -> Unit = {}) {
+
+        val splitPath = path.trim('/').split("/").toMutableList()
+        this.element(splitPath, f)
     }
 
     fun attribute(name: String, value: String) {
diff --git a/sandbox/src/test/kotlin/XmlCombinatorsTest.kt 
b/sandbox/src/test/kotlin/XmlCombinatorsTest.kt
index 721481a..1cc509c 100644
--- a/sandbox/src/test/kotlin/XmlCombinatorsTest.kt
+++ b/sandbox/src/test/kotlin/XmlCombinatorsTest.kt
@@ -22,13 +22,20 @@ package tech.libeufin.sandbox
 import org.junit.Test
 
 class XmlCombinatorsTest {
+
     @Test
     fun testBasicXmlBuilding() {
         val s = constructXml(indent = true) {
             namespace("ebics", "urn:org:ebics:H004")
             root("ebics:ebicsRequest") {
                 attribute("version", "H004")
-                element("foo")
+                element("a/b/c") {
+                    attribute("attribute-of", "c")
+                    element("//d/e/f//") {
+                        attribute("nested", "true")
+                        element("g/h/")
+                    }
+                }
             }
         }
         println(s)

-- 
To stop receiving notification emails like this one, please contact
address@hidden.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]