aboutsummaryrefslogtreecommitdiffstats
path: root/vespajlib/src/main/java/com/yahoo/text/XML.java
diff options
context:
space:
mode:
authorBjørn Christian Seime <bjorncs@yahooinc.com>2023-06-15 14:05:09 +0200
committerBjørn Christian Seime <bjorncs@yahooinc.com>2023-06-15 14:06:27 +0200
commit563128c8fbc3f5fa3b5d4f414904c330ed6491a1 (patch)
tree75dbf488c610545cea6d09358a5f0c15d9e50755 /vespajlib/src/main/java/com/yahoo/text/XML.java
parent37761206b87ec3dad92ce9b418817016e89c842d (diff)
Add helper `XML.getChildValue()`
Diffstat (limited to 'vespajlib/src/main/java/com/yahoo/text/XML.java')
-rw-r--r--vespajlib/src/main/java/com/yahoo/text/XML.java7
1 files changed, 7 insertions, 0 deletions
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.
*