diff options
author | Christian Schneppe <christian@pix-art.de> | 2019-09-12 19:46:20 +0200 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2019-09-12 19:46:20 +0200 |
commit | 88574e39d27a44bab1555f25dde062b1abf602bc (patch) | |
tree | 376b0c3e0bb4d91f5a34d131ee9a2232ecd3eeb6 /src/main/java/de/pixart/messenger/xml/Element.java | |
parent | 8857f9341c46ce1294c56bc5c729e126884be10c (diff) |
when parsing omemo messages ensure we only find one element
Diffstat (limited to 'src/main/java/de/pixart/messenger/xml/Element.java')
-rw-r--r-- | src/main/java/de/pixart/messenger/xml/Element.java | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/main/java/de/pixart/messenger/xml/Element.java b/src/main/java/de/pixart/messenger/xml/Element.java index c833575fa..052dd7947 100644 --- a/src/main/java/de/pixart/messenger/xml/Element.java +++ b/src/main/java/de/pixart/messenger/xml/Element.java @@ -82,6 +82,19 @@ public class Element { return null; } + public Element findChildEnsureSingle(String name, String xmlns) { + final List<Element> results = new ArrayList<>(); + for (Element child : this.children) { + if (name.equals(child.getName()) && xmlns.equals(child.getAttribute("xmlns"))) { + results.add(child); + } + } + if (results.size() == 1) { + return results.get(0); + } + return null; + } + public String findChildContent(String name, String xmlns) { Element element = findChild(name, xmlns); return element == null ? null : element.getContent(); |