Example usage for org.w3c.dom Element setAttribute

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

Introduction

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

Prototype

public void setAttribute(String name, String value) throws DOMException;

Source Link

Document

Adds a new attribute.

Usage

From source file:Main.java

public static Document createDocument(String mainType, String customType) throws ParserConfigurationException {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();
    Document document = builder.newDocument();
    document.setXmlStandalone(false);/*from  w  w  w .j a v a 2 s  . c o  m*/
    Element sync = document.createElement("Sync");
    document.appendChild(sync);
    Element entity = document.createElement("Entity");
    entity.setAttribute("mainType", mainType);
    if (customType.length() > 0)
        entity.setAttribute("customType", customType);
    document.getElementsByTagName("Sync").item(0).appendChild(entity);
    return document;
}

From source file:Main.java

public static void setIntegerAttribute(Element el, String attr, Integer value) {
    if (null != value) {
        el.setAttribute(attr, value.toString());
    }//from  w  w w.java2  s  .  c o m
}

From source file:Main.java

public static void setIdentityAttribute(Document document, String attributeValue) {
    boolean isFound = false;
    NodeList propertyList = document.getElementsByTagName("Property");
    for (int i = 0; i < propertyList.getLength(); i++) {
        Node node = propertyList.item(i);
        for (int j = 0; j < node.getAttributes().getLength(); j++) {
            Node attribute = node.getAttributes().item(j);
            if (attribute.getNodeName().equals("name") && attribute.getNodeValue().equals(attributeValue)) {
                Element element = (Element) node;
                element.setAttribute("isIdentity", "true");
                isFound = true;/* w  w w .j ava 2 s .  c o m*/
                break;
            }
        }
        if (isFound)
            break;
    }
}

From source file:Main.java

public static Element toXML(Point p, Document document) {
    Element result = document.createElement("center");
    result.setAttribute("x", Integer.toString(p.x));
    result.setAttribute("y", Integer.toString(p.y));
    return result;
}

From source file:Main.java

/**
 * A utility  to set the attribute on the given node as the
 * String representation of the given color
 *
 * @param node The node//  w w w  .ja  v  a2  s. c o m
 * @param name The attr name
 * @param value The color
 */
public static void setAttribute(Element node, String name, Color value) {
    node.setAttribute(name, "" + value.getRed() + "," + value.getGreen() + "," + value.getBlue());
}

From source file:Main.java

public static void addAttribute(Element parent, Object name, Object value) {
    if (value == null) {
        parent.setAttribute(name.toString(), "");
    } else {/*  ww  w  . j  av  a 2  s.c  o m*/
        parent.setAttribute(name.toString(), value.toString());
    }
}

From source file:Main.java

public static Element appendResultSetToNode(Element root, String rowTag, ResultSet rs) throws SQLException {
    Document doc = root.getOwnerDocument();

    ResultSetMetaData meta = rs.getMetaData();
    int columnCount = meta.getColumnCount();
    int rowCount = 0;
    while (rs.next()) {
        Element rowElement = doc.createElement(rowTag);
        rowElement.setAttribute("row", "" + rowCount);
        for (int i = 1; i <= columnCount; i++) {
            rowElement.setAttribute(meta.getColumnName(i), rs.getString(i));
        }/*from  w  ww.  j  a v  a  2  s .  com*/
        rowCount++;
        root.appendChild(rowElement);
    }

    return root;
}

From source file:Main.java

public static void edit(Document document) {
    String docNS = "http://www.my-company.com";

    Element order = document.createElementNS(docNS, "order");
    document.appendChild(order);/*  ww w  .  j a v  a 2  s  .c om*/
    order.setAttribute("xmlns", docNS);
}

From source file:Main.java

public static void addNamespaceMapping(Element importsElement, String dictionaryPrefix, String dictionaryUri) {
    Element importElement = importsElement.getOwnerDocument().createElement("import");
    importElement.setAttribute("uri", dictionaryUri);
    importElement.setAttribute("prefix", dictionaryPrefix);
    importsElement.appendChild(importElement);
}

From source file:Main.java

/**
 *
 * @param parent Element/* w  w w  .  j a  v a  2  s.  co m*/
 * @param name String
 * @param value int
 */
public static void appendAttributeNode(Element parent, String name, int value) {
    parent.setAttribute(name, new Integer(value).toString());
}