Java Utililty Methods XML Attribute Copy

List of utility methods to do XML Attribute Copy

Description

The list of methods to do XML Attribute Copy are organized into topic(s).

Method

voidcloneAttribute(Node source, Node destination, String attrName)
clone Attribute
final Node attrNode = source.getAttributes().getNamedItem(attrName);
if (attrNode != null) {
    destination.getAttributes().setNamedItem(attrNode.cloneNode(true));
voidcloneAttributes(Element element, Element targetElement)
clone Attributes
NamedNodeMap attributes = element.getAttributes();
for (int i = 0; i < attributes.getLength(); ++i) {
    Node attribute = attributes.item(i);
    targetElement.setAttribute(attribute.getNodeName(), attribute.getTextContent());
voidcopyAllAttributes(Element from, Element to)
copy All Attributes
NamedNodeMap attrs = from.getAttributes();
int attrCount = attrs.getLength();
for (int i = 0; i < attrCount; ++i) {
    Attr attr = (Attr) attrs.item(i);
    to.setAttributeNS(attr.getNamespaceURI(),  attr.getName(), attr.getValue());
voidcopyAllAttributes(Element source, Element dest, Set ignore)
copy All Attributes
NamedNodeMap attrs = source.getAttributes();
for (int i = 0, size = attrs.getLength(); i < size; i++) {
    Attr attr = (Attr) attrs.item(i);
    if (ignore == null || !ignore.contains(attr.getName())) {
        if (NamedBooleanList.contains(attr.getName()) && "false".equalsIgnoreCase(attr.getValue())) { 
            continue;
        dest.setAttribute(attr.getName(), attr.getValue());
...
voidcopyAttribute(Element source, String srcattr, Element dest, String destattr)
copy a single attribute (if exist)
Attr attr = source.getAttributeNode(srcattr);
if (attr != null) {
    dest.setAttribute(destattr, attr.getValue());
voidcopyAttribute(Element sourceElement, String sourceAttrName, Element visualElement, String visualAttrName)
Copies all attributes from source node to visual node.
if (sourceElement.hasAttribute(sourceAttrName)) {
    String attrValue = sourceElement.getAttribute(sourceAttrName);
    visualElement.setAttribute(visualAttrName, attrValue);
voidcopyAttributeNodes(Element source, Element target)
copy Attribute Nodes
NamedNodeMap sourceAttributes = source.getAttributes();
for (int i = 0; i <= sourceAttributes.getLength() - 1; i++) {
    target.setAttributeNode((Attr) sourceAttributes.item(i).cloneNode(false));
voidcopyAttributes(Element elementFrom, Element elementTo)
Copies all attributes from one element to another in the official way.
NamedNodeMap nodeList = elementFrom.getAttributes();
if (nodeList == null) {
    return;
Attr attrFrom = null;
Attr attrTo = null;
Document documentTo = elementTo.getOwnerDocument();
int len = nodeList.getLength();
...
voidcopyAttributes(Element from, Element to)
Copy the attribues on one element to the other
NamedNodeMap attributes = from.getAttributes();
for (int i = 0; i < attributes.getLength(); i++) {
    Attr node = (Attr) attributes.item(i);
    to.setAttributeNS(node.getNamespaceURI(), node.getName(), node.getValue());
voidcopyAttributes(Element from, Element to, NodeFilter filter)
copies all attributes from one Element to another
if ((from != null) && (to != null)) {
    NamedNodeMap map = from.getAttributes();
    if (filter == null) {
        filter = new NodeFilter() {
            public short acceptNode(Node n) {
                return NodeFilter.FILTER_ACCEPT;
        };
...