[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[libeufin] branch master updated: String-picking XPath helper.
From: |
gnunet |
Subject: |
[libeufin] branch master updated: String-picking XPath helper. |
Date: |
Thu, 26 Mar 2020 09:17:40 +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 f974215 String-picking XPath helper.
f974215 is described below
commit f974215e759a3ecf9d5b65a3f396696aa03e548c
Author: Marcello Stanisci <address@hidden>
AuthorDate: Thu Mar 26 09:17:13 2020 +0100
String-picking XPath helper.
---
nexus/src/test/kotlin/XPathTest.kt | 5 ++++-
util/src/main/kotlin/XMLUtil.kt | 13 ++++++++-----
2 files changed, 12 insertions(+), 6 deletions(-)
diff --git a/nexus/src/test/kotlin/XPathTest.kt
b/nexus/src/test/kotlin/XPathTest.kt
index 2e796fa..388fb6d 100644
--- a/nexus/src/test/kotlin/XPathTest.kt
+++ b/nexus/src/test/kotlin/XPathTest.kt
@@ -15,8 +15,11 @@ class XPathTest {
<node>lorem ipsum</node>
</root>""".trimIndent()
val doc: Document = XMLUtil.parseStringIntoDom(xml)
- val node = XMLUtil.evalXpath(doc, "/*[local-name()='root']")
+ val node = XMLUtil.getNodeFromXpath(doc, "/*[local-name()='root']")
assert(node != null)
+ val text = XMLUtil.getStringFromXpath(doc, "//*[local-name()='node']")
+ assert(text != null)
+ println(text)
}
}
diff --git a/util/src/main/kotlin/XMLUtil.kt b/util/src/main/kotlin/XMLUtil.kt
index 7ce6a3b..1e09586 100644
--- a/util/src/main/kotlin/XMLUtil.kt
+++ b/util/src/main/kotlin/XMLUtil.kt
@@ -90,9 +90,7 @@ class XMLUtil private constructor() {
throw Exception("invalid EBICS XML signature URI:
'${myRef.uri}'")
val xp: XPath = XPathFactory.newInstance().newXPath()
val nodeSet =
xp.compile("//*[@authenticate='true']/descendant-or-self::node()").evaluate(
- myRef.here
- .ownerDocument, XPathConstants
- .NODESET
+ myRef.here.ownerDocument, XPathConstants.NODESET
)
if (nodeSet !is NodeList)
throw Exception("invalid type")
@@ -409,9 +407,14 @@ class XMLUtil private constructor() {
return valResult
}
- fun evalXpath(doc: Document, query: String): Node? {
+ fun getNodeFromXpath(doc: Document, query: String): Node? {
val xpath = XPathFactory.newInstance().newXPath()
- return xpath.evaluate(query, doc, XPathConstants.NODE) as Node
+ return xpath.evaluate(query, doc, XPathConstants.NODE) as Node?
+ }
+
+ fun getStringFromXpath(doc: Document, query: String): String? {
+ val xpath = XPathFactory.newInstance().newXPath()
+ return xpath.evaluate(query, doc, XPathConstants.STRING) as String?
}
}
}
--
To stop receiving notification emails like this one, please contact
address@hidden.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [libeufin] branch master updated: String-picking XPath helper.,
gnunet <=