01: package liquibase.util;
02:
03: import org.w3c.dom.Element;
04: import org.w3c.dom.Node;
05: import org.w3c.dom.NodeList;
06: import org.w3c.dom.Text;
07:
08: /**
09: * Various utility methods for working with XML.
10: */
11: public class XMLUtil {
12: /**
13: * Extracts the text from the given element.
14: * Element.getTextContet() is java5 specific, so we need to use this until we drop 1.4 support.
15: */
16: public static String getTextContent(Element element) {
17: StringBuffer text = new StringBuffer();
18: NodeList childNodes = element.getChildNodes();
19: for (int i = 0; i < childNodes.getLength(); i++) {
20: Node child = childNodes.item(i);
21: if (child instanceof Text) {
22: text.append(child.getNodeValue());
23: }
24: }
25:
26: return text.toString();
27: }
28: }
|