/** * Namespace-aware equals comparison. Returns {@code true} if either * {@link Node#getLocalName} or {@link Node#getNodeName} equals * {@code desiredName}, otherwise returns {@code false}. */ public static boolean nodeNameEquals(Node node, String desiredName) { Assert.notNull(node, "Node must not be null"); Assert.notNull(desiredName, "Desired name must not be null"); return nodeNameMatch(node, desiredName); }
/** * Utility method that returns the first child element identified by its name. * @param ele the DOM element to analyze * @param childEleName the child element name to look for * @return the {@code org.w3c.dom.Element} instance, or {@code null} if none found */ @Nullable public static Element getChildElementByTagName(Element ele, String childEleName) { Assert.notNull(ele, "Element must not be null"); Assert.notNull(childEleName, "Element name must not be null"); NodeList nl = ele.getChildNodes(); for (int i = 0; i < nl.getLength(); i++) { Node node = nl.item(i); if (node instanceof Element && nodeNameMatch(node, childEleName)) { return (Element) node; } } return null; }
/** * Namespace-aware equals comparison. Returns {@code true} if either * {@link Node#getLocalName} or {@link Node#getNodeName} equals * {@code desiredName}, otherwise returns {@code false}. */ public static boolean nodeNameEquals(Node node, String desiredName) { Assert.notNull(node, "Node must not be null"); Assert.notNull(desiredName, "Desired name must not be null"); return nodeNameMatch(node, desiredName); }
/** * Retrieves all child elements of the given DOM element that match any of the given element names. * Only looks at the direct child level of the given element; do not go into further depth * (in contrast to the DOM API's {@code getElementsByTagName} method). * @param ele the DOM element to analyze * @param childEleNames the child element names to look for * @return a List of child {@code org.w3c.dom.Element} instances * @see org.w3c.dom.Element * @see org.w3c.dom.Element#getElementsByTagName */ public static List<Element> getChildElementsByTagName(Element ele, String... childEleNames) { Assert.notNull(ele, "Element must not be null"); Assert.notNull(childEleNames, "Element names collection must not be null"); List<String> childEleNameList = Arrays.asList(childEleNames); NodeList nl = ele.getChildNodes(); List<Element> childEles = new ArrayList<>(); for (int i = 0; i < nl.getLength(); i++) { Node node = nl.item(i); if (node instanceof Element && nodeNameMatch(node, childEleNameList)) { childEles.add((Element) node); } } return childEles; }
/** * Utility method that returns the first child element identified by its name. * @param ele the DOM element to analyze * @param childEleName the child element name to look for * @return the {@code org.w3c.dom.Element} instance, or {@code null} if none found */ @Nullable public static Element getChildElementByTagName(Element ele, String childEleName) { Assert.notNull(ele, "Element must not be null"); Assert.notNull(childEleName, "Element name must not be null"); NodeList nl = ele.getChildNodes(); for (int i = 0; i < nl.getLength(); i++) { Node node = nl.item(i); if (node instanceof Element && nodeNameMatch(node, childEleName)) { return (Element) node; } } return null; }
/** * Retrieves all child elements of the given DOM element that match any of the given element names. * Only looks at the direct child level of the given element; do not go into further depth * (in contrast to the DOM API's {@code getElementsByTagName} method). * @param ele the DOM element to analyze * @param childEleNames the child element names to look for * @return a List of child {@code org.w3c.dom.Element} instances * @see org.w3c.dom.Element * @see org.w3c.dom.Element#getElementsByTagName */ public static List<Element> getChildElementsByTagName(Element ele, String... childEleNames) { Assert.notNull(ele, "Element must not be null"); Assert.notNull(childEleNames, "Element names collection must not be null"); List<String> childEleNameList = Arrays.asList(childEleNames); NodeList nl = ele.getChildNodes(); List<Element> childEles = new ArrayList<>(); for (int i = 0; i < nl.getLength(); i++) { Node node = nl.item(i); if (node instanceof Element && nodeNameMatch(node, childEleNameList)) { childEles.add((Element) node); } } return childEles; }
/** * Namespace-aware equals comparison. Returns <code>true</code> if either {@link Node#getLocalName} or {@link * Node#getNodeName} equals <code>desiredName</code>, otherwise returns <code>false</code>. */ public static boolean nodeNameEquals(Node node, String desiredName) { Assert.notNull(node, "Node must not be null"); Assert.notNull(desiredName, "Desired name must not be null"); return nodeNameMatch(node, desiredName); }
/** * Utility method that returns the first child element identified by its name. * * @param ele the DOM element to analyze * @param childEleName the child element name to look for * @return the <code>org.w3c.dom.Element</code> instance, or <code>null</code> if none found */ public static Element getChildElementByTagName(Element ele, String childEleName) { Assert.notNull(ele, "Element must not be null"); Assert.notNull(childEleName, "Element name must not be null"); NodeList nl = ele.getChildNodes(); for (int i = 0; i < nl.getLength(); i++) { Node node = nl.item(i); if (node instanceof Element && nodeNameMatch(node, childEleName)) { return (Element) node; } } return null; }
/** * Retrieve all child elements of the given DOM element that match any of the given element names. Only look at the * direct child level of the given element; do not go into further depth (in contrast to the DOM API's * <code>getElementsByTagName</code> method). * * @param ele the DOM element to analyze * @param childEleNames the child element names to look for * @return a List of child <code>org.w3c.dom.Element</code> instances * @see org.w3c.dom.Element * @see org.w3c.dom.Element#getElementsByTagName */ public static List<Element> getChildElementsByTagName(Element ele, String[] childEleNames) { Assert.notNull(ele, "Element must not be null"); Assert.notNull(childEleNames, "Element names collection must not be null"); List<String> childEleNameList = Arrays.asList(childEleNames); 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 && nodeNameMatch(node, childEleNameList)) { childEles.add((Element) node); } } return childEles; }
/** * Namespace-aware equals comparison. Returns {@code true} if either * {@link Node#getLocalName} or {@link Node#getNodeName} equals * {@code desiredName}, otherwise returns {@code false}. */ public static boolean nodeNameEquals(Node node, String desiredName) { Assert.notNull(node, "Node must not be null"); Assert.notNull(desiredName, "Desired name must not be null"); return nodeNameMatch(node, desiredName); }
/** * Namespace-aware equals comparison. Returns {@code true} if either * {@link Node#getLocalName} or {@link Node#getNodeName} equals * {@code desiredName}, otherwise returns {@code false}. */ public static boolean nodeNameEquals(Node node, String desiredName) { Assert.notNull(node, "Node must not be null"); Assert.notNull(desiredName, "Desired name must not be null"); return nodeNameMatch(node, desiredName); }
/** * Utility method that returns the first child element identified by its name. * @param ele the DOM element to analyze * @param childEleName the child element name to look for * @return the {@code org.w3c.dom.Element} instance, or {@code null} if none found */ @Nullable public static Element getChildElementByTagName(Element ele, String childEleName) { Assert.notNull(ele, "Element must not be null"); Assert.notNull(childEleName, "Element name must not be null"); NodeList nl = ele.getChildNodes(); for (int i = 0; i < nl.getLength(); i++) { Node node = nl.item(i); if (node instanceof Element && nodeNameMatch(node, childEleName)) { return (Element) node; } } return null; }
/** * Utility method that returns the first child element identified by its name. * @param ele the DOM element to analyze * @param childEleName the child element name to look for * @return the {@code org.w3c.dom.Element} instance, or {@code null} if none found */ @Nullable public static Element getChildElementByTagName(Element ele, String childEleName) { Assert.notNull(ele, "Element must not be null"); Assert.notNull(childEleName, "Element name must not be null"); NodeList nl = ele.getChildNodes(); for (int i = 0; i < nl.getLength(); i++) { Node node = nl.item(i); if (node instanceof Element && nodeNameMatch(node, childEleName)) { return (Element) node; } } return null; }
/** * Retrieves all child elements of the given DOM element that match any of the given element names. * Only looks at the direct child level of the given element; do not go into further depth * (in contrast to the DOM API's {@code getElementsByTagName} method). * @param ele the DOM element to analyze * @param childEleNames the child element names to look for * @return a List of child {@code org.w3c.dom.Element} instances * @see org.w3c.dom.Element * @see org.w3c.dom.Element#getElementsByTagName */ public static List<Element> getChildElementsByTagName(Element ele, String... childEleNames) { Assert.notNull(ele, "Element must not be null"); Assert.notNull(childEleNames, "Element names collection must not be null"); List<String> childEleNameList = Arrays.asList(childEleNames); NodeList nl = ele.getChildNodes(); List<Element> childEles = new ArrayList<>(); for (int i = 0; i < nl.getLength(); i++) { Node node = nl.item(i); if (node instanceof Element && nodeNameMatch(node, childEleNameList)) { childEles.add((Element) node); } } return childEles; }
/** * Retrieves all child elements of the given DOM element that match any of the given element names. * Only looks at the direct child level of the given element; do not go into further depth * (in contrast to the DOM API's {@code getElementsByTagName} method). * @param ele the DOM element to analyze * @param childEleNames the child element names to look for * @return a List of child {@code org.w3c.dom.Element} instances * @see org.w3c.dom.Element * @see org.w3c.dom.Element#getElementsByTagName */ public static List<Element> getChildElementsByTagName(Element ele, String... childEleNames) { Assert.notNull(ele, "Element must not be null"); Assert.notNull(childEleNames, "Element names collection must not be null"); List<String> childEleNameList = Arrays.asList(childEleNames); NodeList nl = ele.getChildNodes(); List<Element> childEles = new ArrayList<>(); for (int i = 0; i < nl.getLength(); i++) { Node node = nl.item(i); if (node instanceof Element && nodeNameMatch(node, childEleNameList)) { childEles.add((Element) node); } } return childEles; }