Skip to content

Commit 7a22aca

Browse files
committed
XML: add cdata utility method for element children
It makes it much more convenient to ask for, say, the value of the one and only "id" element beneath the specified "developer" element.
1 parent 32cdb35 commit 7a22aca

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/main/java/org/scijava/util/XML.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,13 @@ public static String cdata(final Node item) {
241241
return null;
242242
}
243243

244+
/** Gets the CData beneath the given element's specified child. */
245+
public static String cdata(final Element el, final String child) {
246+
NodeList children = el.getElementsByTagName(child);
247+
if (children == null || children.getLength() == 0) return null;
248+
return cdata(children.item(0));
249+
}
250+
244251
// -- Helper methods --
245252

246253
/** Loads an XML document from the given file. */

0 commit comments

Comments
 (0)