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:fitnesse.wiki.WikiPageProperties.java

private void toXml(WikiPageProperty context, String key, Document document, Element parent) {
    Element element = document.createElement(key);

    String value = context.getValue();
    if (context.hasChildren()) {
        if (value != null)
            element.setAttribute("value", value);

        Set<String> childKeys = context.keySet();
        for (String childKey : childKeys) {
            WikiPageProperty child = context.getProperty(childKey);
            if (child == null) {
                System.err.println("Property key \"" + childKey + "\" has null value for {" + context + "}");
            } else {
                toXml(child, childKey, document, element);
            }/*from w  ww.  j a  va 2s.  c  o m*/
        }
    } else if (value != null)
        element.appendChild(document.createTextNode(Utils.escapeHTML(value)));

    parent.appendChild(element);
}

From source file:bpsperf.modelgen.BPMNGenerator.java

private Element addNode(String nodeType, String id, String name) {
    Element node = doc.createElementNS(ns, nodeType);
    node.setAttribute("id", id);
    node.setAttribute("name", name);
    parent.appendChild(node);// w  w w .  j  ava  2  s  .c o  m
    return node;
}

From source file:io.wcm.tooling.commons.contentpackagebuilder.XmlContentBuilder.java

private void setAttributeNamespaceAware(Element element, String key, String value) {
    String namespace = getNamespace(key);
    if (namespace == null) {
        element.setAttribute(ISO9075.encode(key), value);
    } else {/* w w  w .  ja  va 2  s.c  o  m*/
        element.setAttributeNS(namespace, ISO9075.encode(key), value);
    }
}

From source file:com.netspective.sparx.util.xml.XmlSource.java

public static void defineClassAttributes(Element defnElement, Class cls, String attrPrefix) {
    if (cls == null)
        return;/*from   w w  w.ja  v  a2 s .  c  o  m*/

    String className = cls.getName();
    String classFileName = ClassPath.getClassFileName(className);

    defnElement.setAttribute(attrPrefix + "class-name", className);
    defnElement.setAttribute(attrPrefix + "class-file-name", classFileName);

    String classSrcName = classFileName.substring(0, classFileName.lastIndexOf('.')) + ".java";
    if (new File(classSrcName).exists())
        defnElement.setAttribute(attrPrefix + "class-src-name", classSrcName);
}

From source file:de.erdesignerng.model.serializer.xml20.XMLSubjectAreaSerializer.java

@Override
public void serialize(SubjectArea aArea, Document aDocument, Element aRootElement) {

    Element theSubjectAreaElement = addElement(aDocument, aRootElement, SUBJECTAREA);

    // Basisdaten des Modelelementes speichern
    serializeProperties(aDocument, theSubjectAreaElement, aArea);
    theSubjectAreaElement.setAttribute(COLOR, "" + aArea.getColor().getRGB());
    setBooleanAttribute(theSubjectAreaElement, VISIBLE, aArea.isVisible());

    for (Table theTable : aArea.getTables()) {
        Element theTableElement = addElement(aDocument, theSubjectAreaElement, ITEM);
        theTableElement.setAttribute(TABLEREFID, theTable.getSystemId());
    }//ww  w  .java2 s . c om

    for (View theView : aArea.getViews()) {
        Element theViewElement = addElement(aDocument, theSubjectAreaElement, ITEM);
        theViewElement.setAttribute(VIEWREFID, theView.getSystemId());
    }

    for (Comment theComment : aArea.getComments()) {
        Element theCommentElement = addElement(aDocument, theSubjectAreaElement, ITEM);
        theCommentElement.setAttribute(COMMENTREFID, theComment.getSystemId());
    }
}

From source file:XMLWriteTest.java

/**
 * Creates an SVG document of the current drawing.
 * @return the DOM tree of the SVG document
 *///w  w  w  . j a  va 2s .com
public Document buildDocument() {
    Document doc = builder.newDocument();
    Element svgElement = doc.createElement("svg");
    doc.appendChild(svgElement);
    svgElement.setAttribute("width", "" + getWidth());
    svgElement.setAttribute("height", "" + getHeight());
    for (int i = 0; i < rects.size(); i++) {
        Color c = colors.get(i);
        Rectangle2D r = rects.get(i);
        Element rectElement = doc.createElement("rect");
        rectElement.setAttribute("x", "" + r.getX());
        rectElement.setAttribute("y", "" + r.getY());
        rectElement.setAttribute("width", "" + r.getWidth());
        rectElement.setAttribute("height", "" + r.getHeight());
        rectElement.setAttribute("fill", colorToString(c));
        svgElement.appendChild(rectElement);
    }
    return doc;
}

From source file:aurelienribon.gdxsetupui.ProjectUpdate.java

private void writeGwtDefinition(File gwtDefitionFile, List<GwtModule> modules) {
    try {//from  w  w  w . j a va 2 s.  c  o  m
        Document doc = XmlUtils.createParser().parse(gwtDefitionFile);
        Node root = (Node) XmlUtils.xpath("module", doc, XPathConstants.NODE);
        NodeList nodes = (NodeList) XmlUtils.xpath("module/inherits", doc, XPathConstants.NODESET);

        for (int i = 0; i < nodes.getLength(); i++) {
            root.removeChild(nodes.item(i));
        }

        for (GwtModule module : modules) {
            Element elem = doc.createElement("inherits");
            root.appendChild(elem);

            elem.setAttribute("name", module.name);
        }

        XmlUtils.clean(doc);
        String str = XmlUtils.transform(doc);
        FileUtils.writeStringToFile(gwtDefitionFile, str);

    } catch (SAXException ex) {
        throw new RuntimeException(ex);
    } catch (IOException ex) {
        throw new RuntimeException(ex);
    } catch (TransformerException ex) {
        throw new RuntimeException(ex);
    }
}

From source file:de.erdesignerng.model.serializer.xml50.XMLSubjectAreaSerializer.java

@Override
public void serialize(SubjectArea aArea, Document aDocument, Element aRootElement) {

    Element theSubjectAreaElement = addElement(aDocument, aRootElement, SUBJECTAREA);

    // Basisdaten des Modelelementes speichern
    serializeProperties(aDocument, theSubjectAreaElement, aArea);
    theSubjectAreaElement.setAttribute(COLOR, "" + aArea.getColor().getRGB());
    setBooleanAttribute(theSubjectAreaElement, VISIBLE, aArea.isVisible());
    setBooleanAttribute(theSubjectAreaElement, EXPANDED, aArea.isExpanded());

    for (Table theTable : aArea.getTables()) {
        Element theTableElement = addElement(aDocument, theSubjectAreaElement, ITEM);
        theTableElement.setAttribute(TABLEREFID, theTable.getSystemId());
    }/*from   w  w w.  ja v a 2 s  .  c  om*/

    for (View theView : aArea.getViews()) {
        Element theViewElement = addElement(aDocument, theSubjectAreaElement, ITEM);
        theViewElement.setAttribute(VIEWREFID, theView.getSystemId());
    }

    for (Comment theComment : aArea.getComments()) {
        Element theCommentElement = addElement(aDocument, theSubjectAreaElement, ITEM);
        theCommentElement.setAttribute(COMMENTREFID, theComment.getSystemId());
    }
}

From source file:bpsperf.modelgen.BPMNGenerator.java

private Element connect(String sourceId, String targetId, String flowId) {
    Element flow = doc.createElementNS(ns, "sequenceFlow");
    flow.setAttribute("id", flowId);
    flow.setAttribute("sourceRef", sourceId);
    flow.setAttribute("targetRef", targetId);
    parent.appendChild(flow);/*from  www.  ja v a 2s  .c  o m*/
    return flow;
}

From source file:org.callimachusproject.xproc.Pipeline.java

private XdmNode parse(String systemId, InputStream source, String media, XProcConfiguration config)
        throws IOException, SAXException, ParserConfigurationException {
    if (source == null && media == null)
        return null;
    try {//from   w  w w  . ja  v a 2 s.co  m
        FluidType type = new FluidType(InputStream.class, media);
        if (type.isXML())
            return resolver.parse(systemId, source);
        Document doc = DocumentFactory.newInstance().newDocument();
        if (systemId != null) {
            doc.setDocumentURI(systemId);
        }
        Element data = doc.createElementNS(XPROC_STEP, DATA);
        data.setAttribute("content-type", media);
        if (type.isText()) {
            Charset charset = type.getCharset();
            if (charset == null) {
                charset = Charset.forName("UTF-8");
            }
            if (source != null) {
                appendText(new InputStreamReader(source, charset), doc, data);
            }
        } else if (source != null) {
            data.setAttribute("encoding", "base64");
            appendBase64(source, doc, data);
        }

        doc.appendChild(data);
        return config.getProcessor().newDocumentBuilder().wrap(doc);
    } finally {
        if (source != null) {
            source.close();
        }
    }
}