diff options
author | Bjørn Christian Seime <bjorncs@yahooinc.com> | 2023-06-15 14:05:09 +0200 |
---|---|---|
committer | Bjørn Christian Seime <bjorncs@yahooinc.com> | 2023-06-15 14:06:27 +0200 |
commit | 563128c8fbc3f5fa3b5d4f414904c330ed6491a1 (patch) | |
tree | 75dbf488c610545cea6d09358a5f0c15d9e50755 /vespajlib | |
parent | 37761206b87ec3dad92ce9b418817016e89c842d (diff) |
Add helper `XML.getChildValue()`
Diffstat (limited to 'vespajlib')
-rw-r--r-- | vespajlib/abi-spec.json | 1 | ||||
-rw-r--r-- | vespajlib/src/main/java/com/yahoo/text/XML.java | 7 |
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. * |