summaryrefslogtreecommitdiffstats
path: root/vespajlib
diff options
context:
space:
mode:
Diffstat (limited to 'vespajlib')
-rw-r--r--vespajlib/abi-spec.json1
-rw-r--r--vespajlib/src/main/java/com/yahoo/text/XML.java7
2 files changed, 8 insertions, 0 deletions
diff --git a/vespajlib/abi-spec.json b/vespajlib/abi-spec.json
index 36f5d22a4fd..676e212f5c6 100644
--- a/vespajlib/abi-spec.json
+++ b/vespajlib/abi-spec.json
@@ -3375,6 +3375,7 @@
"public static java.util.Optional attribute(java.lang.String, org.w3c.dom.Element)",
"public static java.lang.String getValue(org.w3c.dom.Element)",
"public static org.w3c.dom.Element getChild(org.w3c.dom.Element, java.lang.String)",
+ "public static java.util.Optional getChildValue(org.w3c.dom.Element, java.lang.String)",
"public static java.lang.String getNodePath(org.w3c.dom.Node, java.lang.String)",
"public static boolean isName(java.lang.CharSequence)"
],
diff --git a/vespajlib/src/main/java/com/yahoo/text/XML.java b/vespajlib/src/main/java/com/yahoo/text/XML.java
index 255e6a67429..c2b8a0b2289 100644
--- a/vespajlib/src/main/java/com/yahoo/text/XML.java
+++ b/vespajlib/src/main/java/com/yahoo/text/XML.java
@@ -333,6 +333,13 @@ public class XML {
return (getChildren(e, name).size() >= 1) ? getChildren(e, name).get(0) : null;
}
+ /** @return the value of child with the given name, empty string if no value, or empty if no child with name */
+ public static Optional<String> getChildValue(Element e, String name) {
+ var child = getChild(e, name);
+ if (child == null) return Optional.empty();
+ return Optional.of(getValue(child));
+ }
+
/**
* Returns the path to the given xml node, where each node name is separated by the given separator string.
*