一、前言
关于dorado-core源码包中的com.bstek.dorado.util.xml.DomUtils工具类,通过org.springframework.util.xml.DomUtils类分别实现或复用getTextValue、getChildElementValueByTagName、getChildElements、getFirstChildElement方法功能。
二、源码说明
package com.bstek.dorado.util.xml;@b@@b@import java.util.ArrayList;@b@import java.util.List;@b@import org.w3c.dom.Element;@b@import org.w3c.dom.Node;@b@import org.w3c.dom.NodeList;@b@@b@public abstract class DomUtils@b@{@b@ public static String getTextContent(Element element)@b@ {@b@ return org.springframework.util.xml.DomUtils.getTextValue(element);@b@ }@b@@b@ public static String getChildTextContent(Element elemenet, String childElemenetName)@b@ {@b@ return org.springframework.util.xml.DomUtils.getChildElementValueByTagName(elemenet, childElemenetName);@b@ }@b@@b@ public static boolean isNodeNameEquals(Node node, String desiredName)@b@ {@b@ return org.springframework.util.xml.DomUtils.nodeNameEquals(node, desiredName);@b@ }@b@@b@ public static Element getChildByTagName(Element element, String childElementName)@b@ {@b@ return org.springframework.util.xml.DomUtils.getChildElementByTagName(element, childElementName);@b@ }@b@@b@ public static List<Element> getChildrenByTagName(Element element, String childElementName)@b@ {@b@ return org.springframework.util.xml.DomUtils.getChildElementsByTagName(element, childElementName);@b@ }@b@@b@ public static List<Element> getChildElements(Element element)@b@ {@b@ List list = new ArrayList();@b@ NodeList nodeList = element.getChildNodes();@b@ int size = nodeList.getLength();@b@ for (int i = 0; i < size; ++i) {@b@ Node childNode = nodeList.item(i);@b@ if (childNode instanceof Element)@b@ list.add((Element)childNode);@b@ }@b@@b@ return list;@b@ }@b@@b@ public static Element getFirstChildElement(Element element)@b@ {@b@ NodeList nodeList = element.getChildNodes();@b@ int size = nodeList.getLength();@b@ for (int i = 0; i < size; ++i) {@b@ Node childNode = nodeList.item(i);@b@ if (childNode instanceof Element)@b@ return ((Element)childNode);@b@ }@b@@b@ return null;@b@ }@b@}