Example usage for org.w3c.dom NamedNodeMap removeNamedItem

List of usage examples for org.w3c.dom NamedNodeMap removeNamedItem

Introduction

In this page you can find the example usage for org.w3c.dom NamedNodeMap removeNamedItem.

Prototype

public Node removeNamedItem(String name) throws DOMException;

Source Link

Document

Removes a node specified by name.

Usage

From source file:Main.java

public static void removeAllAttributes(Node node, String attrName) {

    // check if this node contains the attribute and remove it
    NamedNodeMap attrs = node.getAttributes();
    if (attrs != null && attrs.getNamedItem(attrName) != null) {
        attrs.removeNamedItem(attrName);
    }/*from  w  w  w  . j ava 2s  .  co  m*/

    // process recursively all children
    NodeList list = node.getChildNodes();
    for (int i = 0; i < list.getLength(); i++) {
        // Get child node
        Node childNode = list.item(i);

        // Visit child node
        removeAllAttributes(childNode, attrName);
    }
}

From source file:Main.java

public static void removeAttribute(Node parent, String name, String value, boolean recursive) {
    NamedNodeMap nnm = parent.getAttributes();
    if (nnm != null) {
        if (value == null) {
            nnm.removeNamedItem(name);
        } else {//from   w w  w.  jav a  2  s .  c  om
            Node attr = nnm.getNamedItem(name);
            if (attr != null) {
                String attrVal = attr.getNodeValue();
                if (value.equals(attrVal)) {
                    nnm.removeNamedItem(name);
                }
            }
        }
    }
    if (recursive) {
        for (Node child = parent.getFirstChild(); child != null; child = child.getNextSibling()) {
            removeAttribute(child, name, value, recursive);
        }
    }
}

From source file:Main.java

/**
 *  Removes a named attribute of a Node<p>
 *  @param node The node to search/*from   w  w w  . j  av a  2s  .  c  o m*/
 *  @param attr The name of the attribute to remove
 */
public synchronized static void removeAttribute(Node node, String attr) {
    if (node == null)
        throw new IllegalArgumentException("Node argument cannot be null");
    if (attr == null)
        throw new IllegalArgumentException("Node attribute argument cannot be null");

    NamedNodeMap map = node.getAttributes();
    if (map != null) {
        Node an = map.getNamedItem(attr);
        if (an != null)
            map.removeNamedItem(attr);
    }
}

From source file:Main.java

/** Remove stray "xmlns" default namespace element that seems to get left over even after removing namespacing from nodes.
 * @param node node to process/*from   w  w  w. ja  va2s. c  o  m*/
 */
public static void removeXmlNsAttribute(final Node node) {
    final NamedNodeMap attr = node.getAttributes();
    for (int i = 0; i < attr.getLength(); i++) {
        final Node item = attr.item(i);
        if (ATTR_XMLNS.equals(item.getNodeName())) {
            attr.removeNamedItem(ATTR_XMLNS);
            return;
        }
    }
}

From source file:Main.java

public static void removeNodeAttributes(Node node) {

    NamedNodeMap attrs = node.getAttributes();

    if ((attrs != null) && (attrs.getLength() > 0)) {
        String[] names = new String[attrs.getLength()];
        for (int i = 0; i < names.length; i++) {
            names[i] = attrs.item(i).getNodeName();
        }//from www.j av a  2s.  c om
        for (int i = 0; i < names.length; i++) {
            attrs.removeNamedItem(names[i]);
        }
    }

}

From source file:edu.eurac.commul.pepperModules.mmax2.Salt2MMAXMapping.java

public static SAnnotationNameSpaceMatchCondition parseSAnnotationNameSpaceMatchCondition(Node node) {
    NamedNodeMap attributes = node.getAttributes();
    Node nsAttributeNode = attributes.getNamedItem(SANN_NS_REGEXP);
    String nsRegExp = null;/*from w  ww  .  j  a  va 2 s.  co  m*/
    if (nsAttributeNode != null) {
        nsRegExp = nsAttributeNode.getNodeValue();
        attributes.removeNamedItem(SANN_NS_REGEXP);
    } else {
        throw new PepperModuleException("'" + SANN_NS_REGEXP
                + "' attribute not found on SAnnotation NameSpace Match Condition '" + node + "'");
    }
    if (attributes.getLength() != 0) {
        throw new PepperModuleException(
                "Additional unexpected attributes found on SAnnotation NameSpace Match Condition '" + node
                        + "'");
    }

    return new SAnnotationNameSpaceMatchCondition(Pattern.compile(nsRegExp));
}

From source file:edu.eurac.commul.pepperModules.mmax2.Salt2MMAXMapping.java

public static SAnnotationSNameMatchCondition parseSAnnotationSNameMatchCondition(Node node) {
    NamedNodeMap attributes = node.getAttributes();
    Node snameAttributeNode = attributes.getNamedItem(SANN_SNAME_REGEXP);
    String nameRegExp = null;//ww  w.  ja v  a2 s . co  m
    if (snameAttributeNode != null) {
        nameRegExp = snameAttributeNode.getNodeValue();
        attributes.removeNamedItem(SANN_SNAME_REGEXP);
    } else {
        throw new PepperModuleException("'" + SANN_SNAME_REGEXP
                + "' attribute not found on SAnnotation SName Match Condition '" + node + "'");
    }
    if (attributes.getLength() != 0) {
        throw new PepperModuleException(
                "Additional unexpected attributes found on SAnnotation SName Match Condition '" + node + "'");
    }

    return new SAnnotationSNameMatchCondition(Pattern.compile(nameRegExp));
}

From source file:edu.eurac.commul.pepperModules.mmax2.Salt2MMAXMapping.java

public static SRelationSNameMatchCondition parseSRelationSNameMatchCondition(Node node) {
    NamedNodeMap attributes = node.getAttributes();
    Node snameAttributeNode = attributes.getNamedItem(SREL_SNAME_REGEXP);
    String snameRegExp = null;/*  w w w. j a v a 2 s.com*/
    if (snameAttributeNode != null) {
        snameRegExp = snameAttributeNode.getNodeValue();
        attributes.removeNamedItem(SREL_SNAME_REGEXP);
    } else {
        throw new PepperModuleException("'" + SREL_SNAME_REGEXP
                + " attribute not found on SRelation SName Match Condition '" + node + "'");
    }
    if (attributes.getLength() != 0) {
        throw new PepperModuleException(
                "Additional unexpected attributes found on SRelation SName Match Condition '" + node + "'");
    }

    return new SRelationSNameMatchCondition(Pattern.compile(snameRegExp));
}

From source file:edu.eurac.commul.pepperModules.mmax2.Salt2MMAXMapping.java

public static SRelationSTypeMatchCondition parseSRelationSTypeMatchCondition(Node node) {
    NamedNodeMap attributes = node.getAttributes();
    Node stypeAttributeNode = attributes.getNamedItem(SREL_STYPE_REGEXP);
    String stypeRegExp = null;/*from w ww .ja  v a2s  .  c o  m*/
    if (stypeAttributeNode != null) {
        stypeRegExp = stypeAttributeNode.getNodeValue();
        attributes.removeNamedItem(SREL_STYPE_REGEXP);
    } else {
        throw new PepperModuleException("'" + SREL_STYPE_REGEXP
                + " attribute not found on SRelation SType Match Condition '" + node + "'");
    }
    if (attributes.getLength() != 0) {
        throw new PepperModuleException(
                "Additional unexpected attributes found on SRelation SType Match Condition '" + node + "'");
    }

    return new SRelationSTypeMatchCondition(Pattern.compile(stypeRegExp));
}

From source file:edu.eurac.commul.pepperModules.mmax2.Salt2MMAXMapping.java

public static SAnnotationSLayerMatchCondition parseSAnnotationSLayerMatchCondition(Node node) {
    NamedNodeMap attributes = node.getAttributes();
    Node slayerAttributeNode = attributes.getNamedItem(SANN_SLAYER_REGEXP);
    String slayerRegExp = null;//w w  w .  j  a va 2  s  .c om
    if (slayerAttributeNode != null) {
        slayerRegExp = slayerAttributeNode.getNodeValue();
        attributes.removeNamedItem(SANN_SLAYER_REGEXP);
    } else {
        throw new PepperModuleException("'" + SANN_SLAYER_REGEXP
                + " attribute not found on SAnnotation SLayer Match Condition '" + node + "'");
    }
    if (attributes.getLength() != 0) {
        throw new PepperModuleException(
                "Additional unexpected attributes found on SAnnnotation SLayer Match Condition '" + node + "'");
    }

    return new SAnnotationSLayerMatchCondition(Pattern.compile(slayerRegExp));
}