Java Code Examples for nu.xom.Element#getAttribute()

The following examples show how to use nu.xom.Element#getAttribute() . 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: XOMTreeBuilder.java    From caja with Apache License 2.0 6 votes vote down vote up
@Override
protected void addAttributesToElement(Element element, HtmlAttributes attributes)
        throws SAXException {
    try {
        for (int i = 0; i < attributes.getLength(); i++) {
            String localName = attributes.getLocalName(i);
            String uri = attributes.getURI(i);
            if (element.getAttribute(localName, uri) == null) {
                element.addAttribute(nodeFactory.makeAttribute(localName,
                        uri, attributes.getValue(i),
                        attributes.getType(i) == "ID" ? Attribute.Type.ID
                                : Attribute.Type.CDATA));
            }
        }
    } catch (XMLException e) {
        fatal(e);
    }
}
 
Example 2
Source File: XOMTreeBuilder.java    From caja with Apache License 2.0 6 votes vote down vote up
@Override
protected Element shallowClone(Element element) throws SAXException {
    try {
        Element rv = nodeFactory.makeElement(element.getLocalName(),
                element.getNamespaceURI());
        for (int i = 0; i < element.getAttributeCount(); i++) {
            Attribute attribute = element.getAttribute(i);
            rv.addAttribute(nodeFactory.makeAttribute(
                    attribute.getLocalName(), attribute.getNamespaceURI(),
                    attribute.getValue(), attribute.getType()));
        }
        return rv;
    } catch (XMLException e) {
        fatal(e);
        throw new RuntimeException("Unreachable");
    }
}