Java Code Examples for com.gargoylesoftware.htmlunit.html.DomElement#getChildren()

The following examples show how to use com.gargoylesoftware.htmlunit.html.DomElement#getChildren() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XmlUtils.java    From htmlunit with Apache License 2.0 6 votes vote down vote up
/**
 * Search for the prefix associated with specified namespace URI.
 * @param element the element to start searching from
 * @param namespace the namespace prefix
 * @return the prefix bound to the namespace URI; or null if there is no such namespace
 */
public static String lookupPrefix(final DomElement element, final String namespace) {
    final Map<String, DomAttr> attributes = element.getAttributesMap();
    for (final Map.Entry<String, DomAttr> entry : attributes.entrySet()) {
        final String name = entry.getKey();
        final DomAttr value = entry.getValue();
        if (name.startsWith("xmlns:") && value.getValue().equals(namespace)) {
            return name.substring(6);
        }
    }
    for (final DomNode child : element.getChildren()) {
        if (child instanceof DomElement) {
            final String prefix = lookupPrefix((DomElement) child, namespace);
            if (prefix != null) {
                return prefix;
            }
        }
    }
    return null;
}
 
Example 2
Source File: HtmlUnitPrefixResolver.java    From htmlunit with Apache License 2.0 6 votes vote down vote up
private String getNamespace(final DomElement element, final String prefix) {
    final Map<String, DomAttr> attributes = element.getAttributesMap();
    final String xmlns = "xmlns:";
    final int xmlnsLength = xmlns.length();

    for (final Map.Entry<String, DomAttr> entry : attributes.entrySet()) {
        final String name = entry.getKey();
        if (name.startsWith(xmlns) && name.regionMatches(xmlnsLength, prefix, 0, prefix.length())) {
            return entry.getValue().getValue();
        }
    }
    for (final DomNode child : element.getChildren()) {
        if (child instanceof DomElement) {
            final String namespace = getNamespace((DomElement) child, prefix);
            if (namespace != null) {
                return namespace;
            }
        }
    }
    return null;
}
 
Example 3
Source File: XmlUtil.java    From HtmlUnit-Android with Apache License 2.0 6 votes vote down vote up
/**
 * Search for the prefix associated with specified namespace URI.
 * @param element the element to start searching from
 * @param namespace the namespace prefix
 * @return the prefix bound to the namespace URI; or null if there is no such namespace
 */
public static String lookupPrefix(final DomElement element, final String namespace) {
    final Map<String, DomAttr> attributes = element.getAttributesMap();
    for (final Map.Entry<String, DomAttr> entry : attributes.entrySet()) {
        final String name = entry.getKey();
        final DomAttr value = entry.getValue();
        if (name.startsWith("xmlns:") && value.getValue().equals(namespace)) {
            return name.substring(6);
        }
    }
    for (final DomNode child : element.getChildren()) {
        if (child instanceof DomElement) {
            final String prefix = lookupPrefix((DomElement) child, namespace);
            if (prefix != null) {
                return prefix;
            }
        }
    }
    return null;
}
 
Example 4
Source File: HtmlUnitPrefixResolver.java    From HtmlUnit-Android with Apache License 2.0 6 votes vote down vote up
private String getNamespace(final DomElement element, final String prefix) {
    final Map<String, DomAttr> attributes = element.getAttributesMap();
    final String xmlns = "xmlns:";
    final int xmlnsLength = xmlns.length();

    for (final Map.Entry<String, DomAttr> entry : attributes.entrySet()) {
        final String name = entry.getKey();
        if (name.startsWith(xmlns) && name.regionMatches(xmlnsLength, prefix, 0, prefix.length())) {
            return entry.getValue().getValue();
        }
    }
    for (final DomNode child : element.getChildren()) {
        if (child instanceof DomElement) {
            final String namespace = getNamespace((DomElement) child, prefix);
            if (namespace != null) {
                return namespace;
            }
        }
    }
    return null;
}
 
Example 5
Source File: XMLDOMElement.java    From htmlunit with Apache License 2.0 5 votes vote down vote up
private void normalize(final DomElement domElement) {
    for (DomNode domNode : domElement.getChildren()) {
        if (domNode instanceof DomElement) {
            domNode.normalize();
            normalize((DomElement) domNode);
        }
    }
}
 
Example 6
Source File: XMLDOMElement.java    From HtmlUnit-Android with Apache License 2.0 5 votes vote down vote up
private void normalize(final DomElement domElement) {
    for (DomNode domNode : domElement.getChildren()) {
        if (domNode instanceof DomElement) {
            domNode.normalize();
            normalize((DomElement) domNode);
        }
    }
}