gnunet-svn
[Top][All Lists]
Advanced

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

[libeufin] 01/02: Simple XPath test case.


From: gnunet
Subject: [libeufin] 01/02: Simple XPath test case.
Date: Thu, 26 Mar 2020 09:10:30 +0100

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

marcello pushed a commit to branch master
in repository libeufin.

commit 6f1d7f31a73848a9dfb762b6a2fe408e3024e407
Author: Marcello Stanisci <address@hidden>
AuthorDate: Thu Mar 26 08:32:03 2020 +0100

    Simple XPath test case.
---
 nexus/src/test/kotlin/XPathTest.kt | 22 ++++++++++++++++++++++
 util/src/main/kotlin/XMLUtil.kt    |  4 ++--
 2 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/nexus/src/test/kotlin/XPathTest.kt 
b/nexus/src/test/kotlin/XPathTest.kt
new file mode 100644
index 0000000..fe12db3
--- /dev/null
+++ b/nexus/src/test/kotlin/XPathTest.kt
@@ -0,0 +1,22 @@
+package tech.libeufin.nexus
+
+import org.junit.Test
+import org.w3c.dom.Document
+import tech.libeufin.util.XMLUtil
+
+
+class XPathTest {
+
+    @Test
+    fun pickDataFromSimpleXml() {
+        val xml = """
+            <root>
+              <node>lorem ipsum</node>
+            </root>""".trimIndent()
+        val doc: Document = tech.libeufin.util.XMLUtil.parseStringIntoDom(xml)
+        val nodeSlashes = XMLUtil.evalXpath(doc, "/root/node/text()")
+        println(nodeSlashes?.nodeValue) 
+        val nodeDoubleSlashes = XMLUtil.evalXpath(doc, "//node/text()")
+        println(nodeDoubleSlashes?.nodeValue)
+    }
+}
\ No newline at end of file
diff --git a/util/src/main/kotlin/XMLUtil.kt b/util/src/main/kotlin/XMLUtil.kt
index d7e1563..7ce6a3b 100644
--- a/util/src/main/kotlin/XMLUtil.kt
+++ b/util/src/main/kotlin/XMLUtil.kt
@@ -409,9 +409,9 @@ class XMLUtil private constructor() {
             return valResult
         }
 
-        fun getStringViaXpath(doc: Document, query: String): String {
+        fun evalXpath(doc: Document, query: String): Node? {
             val xpath = XPathFactory.newInstance().newXPath()
-            return xpath.compile(query).evaluate(doc, 
XPathConstants.STRING).toString()
+            return xpath.evaluate(query, doc, XPathConstants.NODE) as Node
         }
     }
 }

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



reply via email to

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