Example usage for org.w3c.dom Element removeAttribute

List of usage examples for org.w3c.dom Element removeAttribute

Introduction

In this page you can find the example usage for org.w3c.dom Element removeAttribute.

Prototype

public void removeAttribute(String name) throws DOMException;

Source Link

Document

Removes an attribute by name.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setValidating(true);// w  ww .j  a v  a2  s .c  om
    factory.setExpandEntityReferences(false);
    Document doc = factory.newDocumentBuilder().parse(new File("filename"));
    Element element = doc.getElementById("key1");

    element.setAttribute("newAttrName", "attrValue");
    element.setAttribute("newAttrName", "<>&\"'");
    element.removeAttribute("value");
    boolean has = element.hasAttribute("value"); // true
    String attrValue = element.getAttribute("value"); // mydefault
}

From source file:Main.java

public static void removeAttribute(Element node, String name) {
    node.removeAttribute(name);
}

From source file:Main.java

public static void delAttribute(Document doc) {
    Element root = doc.getDocumentElement();
    Element person = (Element) root.getFirstChild();
    person.removeAttribute("number");
    person.removeAttribute("dept");
}

From source file:Main.java

/**
 * Remove an attribute from the specified element
 *//*w w  w.j av a  2  s.c  o m*/
public static void removeAttribute(Element element, String name) {
    element.removeAttribute(name);
}

From source file:Main.java

/**
 * Remove <tt>xml:base</tt> attributes from the given node and all of its
 * descendants. According to section 1.3.4 of the DOM Level 3 Core
 * specification, when expanding an external entity reference, DOM parser
 * will add <tt>xml:base</tt> attributes to all elements appearing in the
 * external entity. These attributes don't appear in the reference output
 * files provided in the test suite (see
 * {@link XMLConformanceTest#getOutput()}). This method can be used to
 * remove <tt>xml:base</tt> attributes in DOM documents.
 * //from   w  w w . j  ava2 s . c  o  m
 * @param node
 *            the node to process
 */
public static void removeXmlBaseAttributes(Node node) {
    if (node.getNodeType() == Node.ELEMENT_NODE) {
        Element element = (Element) node;
        element.removeAttribute("xml:base");
    }
    Node child = node.getFirstChild();
    while (child != null) {
        removeXmlBaseAttributes(child);
        child = child.getNextSibling();
    }
}

From source file:com.modelmetrics.common.sforce.util.MessageElementBuilder.java

public static MessageElement getMessageElement(String name, Object value) throws Exception {

    MessageElement me = new MessageElement("", name); // , value);
    me.setObjectValue(value);/*from  w ww . j ava2  s. c  om*/
    Element e = me.getAsDOM();
    e.removeAttribute("xsi:type");
    e.removeAttribute("xmlns:ns1");
    e.removeAttribute("xmlns:xsd");
    e.removeAttribute("xmlns:xsi");

    me = new MessageElement(e);

    //      log.debug("Message element is: " + me.getAsString());

    return me;
}

From source file:Main.java

public static void tTestSetSampleSignificane(Node sampleNode, boolean different) {
    Attr attr = sampleNode.getOwnerDocument().createAttribute("ttest");
    if (different)
        attr.setNodeValue("H1");
    else//  w  ww .j a va 2 s  .c o  m
        attr.setNodeValue("H0");
    // System.out.println(attr.getNodeValue());
    Element e = (Element) sampleNode;
    e.setAttributeNode(attr);
    e.removeAttribute("ttest-level");
}

From source file:Main.java

public static void removeAttributeFromElement(Element element, String attr) {
    if (element != null && element.hasAttribute(attr)) {
        element.removeAttribute(attr);
    }/*  w w w  .j a v a 2  s. c  o  m*/
}

From source file:Main.java

public static void setXsdSchema(Node node, String schemaURL) {
    Document doc;/* w  ww .  ja  v  a2  s.co  m*/
    if (node.getNodeType() != Node.DOCUMENT_NODE) {
        doc = node.getOwnerDocument();
    } else {
        doc = (Document) node;
    }
    Element root = doc.getDocumentElement();
    if (schemaURL == null) {
        root.removeAttribute("xmlns:xsi");
        root.removeAttribute("xsi:noNamespaceSchemaLocation");
    } else {
        root.setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
        root.setAttribute("xsi:noNamespaceSchemaLocation", schemaURL);
    }
}

From source file:Main.java

License:asdf

public static void dom(Element element) {
    element.setAttribute("newAttrName", "attrValue");
    element.setAttribute("newAttrName", "<>&\"'");
    element.removeAttribute("value");
    boolean has = element.hasAttribute("value"); // true
    System.out.println(has);/*www.  j av  a 2s .c  o m*/
    String attrValue = element.getAttribute("value"); // mydefault
    System.out.println(attrValue);
}