Added DomUtils.getChildElements() method. Also refactored ConfigBeanDefinitionParser.parse() to use it.

This commit is contained in:
Luke Taylor
2010-05-14 16:07:39 +00:00
parent 9f9a27a1d8
commit 3f885d0302
6 changed files with 33 additions and 17 deletions

View File

@@ -22,3 +22,4 @@
</ivy:makepom>
</target>
</project>

View File

@@ -38,6 +38,7 @@ import org.springframework.util.Assert;
* @author Rob Harrop
* @author Costin Leau
* @author Arjen Poutsma
* @author Luke Taylor
* @see org.w3c.dom.Node
* @see org.w3c.dom.Element
* @since 1.2
@@ -117,6 +118,25 @@ public abstract class DomUtils {
return (child != null ? getTextValue(child) : null);
}
/**
* Retrieve all child elements of the given DOM element
* @param ele the DOM element to analyze
* @return a List of child <code>org.w3c.dom.Element</code> instances
*/
public static List<Element> getChildElements(Element ele) {
Assert.notNull(ele, "Element must not be null");
NodeList nl = ele.getChildNodes();
List<Element> childEles = new ArrayList<Element>();
for (int i = 0; i < nl.getLength(); i++) {
Node node = nl.item(i);
if (node instanceof Element) {
childEles.add((Element) node);
}
}
return childEles;
}
/**
* Extract the text value from the given DOM element, ignoring XML comments. <p>Appends all CharacterData nodes and
* EntityReference nodes into a single String value, excluding Comment nodes.