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 main(String[] argv) throws Exception {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setValidating(true);// w  w w.j a v  a  2 s. c o  m
    factory.setExpandEntityReferences(false);
    Document doc = factory.newDocumentBuilder().parse(new File("filename"));
    Element element = doc.getElementById("key1");
    NamedNodeMap attrs = element.getAttributes();
    while (attrs.getLength() > 0) {
        attrs.removeNamedItem(attrs.item(0).getNodeName());
    }
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setValidating(true);/*from   www .  ja v a 2  s  .c o m*/
    factory.setExpandEntityReferences(false);

    Document doc = factory.newDocumentBuilder().parse(new File("filename"));
    Element element = doc.getElementById("key1");

    NamedNodeMap attrs = element.getAttributes();
    String[] names = new String[attrs.getLength()];
    for (int i = 0; i < names.length; i++) {
        names[i] = attrs.item(i).getNodeName();
    }
    for (int i = 0; i < names.length; i++) {
        attrs.removeNamedItem(names[i]);
    }
}

From source file:Main.java

public static void removeAttribute(Node node, String attName) {
    NamedNodeMap attributes = node.getAttributes();
    attributes.removeNamedItem(attName);
}

From source file:Main.java

License:asdf

public static void dom(Element element) {
    NamedNodeMap attrs = element.getAttributes();
    while (attrs.getLength() > 0) {
        attrs.removeNamedItem(attrs.item(0).getNodeName());
    }/*from  w  w  w .jav a 2 s. c o  m*/
}

From source file:Main.java

public static Node removeNamedItem(final NamedNodeMap nodeMap, final String name) {
    return nodeMap == null ? null : nodeMap.removeNamedItem(name);
}

From source file:Main.java

public static Object getPropertyValue(Element element) {
    NamedNodeMap map = element.getAttributes();
    map.removeNamedItem(NAME_ATTR);

    if (map.item(0).getNodeName().equals(STRING_ATTR))
        return map.item(0).getNodeValue();
    else if (map.item(0).getNodeName().equals(INTEGER_ATTR))
        return new Integer(map.item(0).getNodeValue());
    else if (map.item(0).getNodeName().equals(DOUBLE_ATTR))
        return new Double(map.item(0).getNodeValue());
    else if (map.item(0).getNodeName().equals(FLOAT_ATTR))
        return new Float(map.item(0).getNodeValue());
    else if (map.item(0).getNodeName().equals(BOOLEAN_ATTR))
        return Boolean.valueOf(map.item(0).getNodeValue());
    else if (map.item(0).getNodeName().equals(COLOR_ATTR)) {
        String[] rgb = map.item(0).getNodeValue().split(",");
        return new Color(new Integer(rgb[0]), new Integer(rgb[1]), new Integer(rgb[2]));
    } else if (map.item(0).getNodeName().equals(FONT_ATTR)) {
        String[] font = map.item(0).getNodeValue().split(",");
        return new Font(font[0], new Integer(font[1]), new Integer(font[2]));
    } else {/*w w  w.  java  2  s  .  c o m*/
        return null;
    }
}

From source file:Main.java

public static void removeValue(NamedNodeMap values, String name) {
    if (values.getNamedItem(name) != null) {
        values.removeNamedItem(name);
    }/*from  www . j a  va  2 s.  c  om*/
}

From source file:Main.java

public static Object getPropertyValue(Element element) {
    NamedNodeMap map = element.getAttributes();
    map.removeNamedItem(NAME_ATTR);

    if (map.item(0).getNodeName().equals(STRING_ATTR)) {
        return map.item(0).getNodeValue();
    } else if (map.item(0).getNodeName().equals(INTEGER_ATTR)) {
        return new Integer(map.item(0).getNodeValue());
    } else if (map.item(0).getNodeName().equals(DOUBLE_ATTR)) {
        return new Double(map.item(0).getNodeValue());
    } else if (map.item(0).getNodeName().equals(FLOAT_ATTR)) {
        return new Float(map.item(0).getNodeValue());
    } else if (map.item(0).getNodeName().equals(BOOLEAN_ATTR)) {
        return Boolean.valueOf(map.item(0).getNodeValue());
    } else if (map.item(0).getNodeName().equals(COLOR_ATTR)) {
        String[] rgb = map.item(0).getNodeValue().split(",");
        return new Color(new Integer(rgb[0]), new Integer(rgb[1]), new Integer(rgb[2]));
    } else if (map.item(0).getNodeName().equals(FONT_ATTR)) {
        String[] font = map.item(0).getNodeValue().split(",");
        return new Font(font[0], new Integer(font[1]), new Integer(font[2]));
    } else {//from   ww  w . j av a 2s.co  m
        return null;
    }
}

From source file:Main.java

private static void clearAttributes(Node node) {
    final NamedNodeMap attributes = node.getAttributes();
    while (attributes.getLength() > 0) {
        attributes.removeNamedItem(attributes.item(0).getNodeName());
    }//from w  w w  . j  a va2  s  .  c  o m
}

From source file:Main.java

public static void removeNodeAttribute(Node node, String name) {

    if (node.hasAttributes()) {

        NamedNodeMap attrs = node.getAttributes();
        if (attrs.getNamedItem(name) != null) {
            attrs.removeNamedItem(name);
        }//w w  w .ja v  a  2  s .  c om
    }

}