Example usage for org.w3c.dom Element setAttributeNode

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

Introduction

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

Prototype

public Attr setAttributeNode(Attr newAttr) throws DOMException;

Source Link

Document

Adds a new attribute node.

Usage

From source file:clus.statistic.RegressionStatBinaryNomiss.java

@Override
public Element getPredictElement(Document doc) {
    Element stats = doc.createElement("RegressionStatBinaryNomiss");
    NumberFormat fr = ClusFormat.SIX_AFTER_DOT;
    Attr examples = doc.createAttribute("examples");
    examples.setValue(fr.format(m_SumWeight));
    stats.setAttributeNode(examples);
    for (int i = 0; i < m_NbAttrs; i++) {
        Element attr = doc.createElement("Target");
        Attr name = doc.createAttribute("name");
        name.setValue(m_Attrs[i].getName());
        attr.setAttributeNode(name);//from   w  w w.j  ava2  s  .c  om
        attr.setTextContent(fr.format(getMean(i)));
        stats.appendChild(attr);
    }
    return stats;
}

From source file:de.betterform.connector.ant.AntSubmissionHandler.java

public Map submit(Submission submission, Node instance) throws XFormsException {
    LOGGER.debug("AntSubmissionHandler.submit()");
    ByteArrayOutputStream stream = new ByteArrayOutputStream();

    if (submission.getMethod().equals("get")) {
        try {/*from w ww.j  a v  a  2s  . c o m*/
            String uri = getURI();
            ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
            ByteArrayOutputStream errorStream = new ByteArrayOutputStream();

            String buildFilePath = (new URI(uri)).getSchemeSpecificPart()
                    .substring((new URI(uri)).getSchemeSpecificPart().indexOf(':') + 1);
            if (!"".equals(buildFilePath)) {
                File buildFile = new File(buildFilePath);
                String target = null;
                if (uri.contains("#")) {
                    //got Traget from uri
                    target = uri.substring(uri.indexOf('#') + 1);
                } else if (((Document) instance).getElementsByTagName("target").item(0) != null) {
                    //got target from xform
                    target = ((Document) instance).getElementsByTagName("target").item(0).getTextContent();
                } else {
                    // use default target
                    target = "default";
                }

                LOGGER.debug("AntSubmissionHandler.runTarget() BuildFile: " + buildFile.getAbsolutePath()
                        + " with Target:" + target);
                runTarget(buildFile, target, outputStream, errorStream);

                DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
                factory.setNamespaceAware(true);
                factory.setValidating(false);
                Document document = factory.newDocumentBuilder().newDocument();
                document.appendChild(document.createElementNS(null, "ant"));

                Element rootElement = document.getDocumentElement();
                Attr filename = document.createAttribute("fileName");
                filename.setValue(buildFile.getName());
                rootElement.setAttributeNode(filename);
                Element element = document.createElement("buildFile");
                DOMUtil.setElementValue(element, buildFile.getAbsolutePath());
                rootElement.appendChild(element);

                element = document.createElement("target");
                DOMUtil.setElementValue(element, target);
                rootElement.appendChild(element);

                element = document.createElement("output-stream");
                DOMUtil.setElementValue(element, outputStream.toString());
                rootElement.appendChild(element);

                element = document.createElement("error-stream");
                DOMUtil.setElementValue(element, errorStream.toString());
                rootElement.appendChild(element);
                DOMUtil.prettyPrintDOM(document, stream);
            } else {
                throw new XFormsException("submission method '" + submission.getMethod() + "' at: "
                        + DOMUtil.getCanonicalPath(submission.getElement()) + " not supported");
            }
        } catch (Exception e) {
            throw new XFormsException(e);
        }
    } else {
        throw new XFormsException("submission method '" + submission.getMethod() + "' at: "
                + DOMUtil.getCanonicalPath(submission.getElement()) + " not supported");
    }

    Map response = new HashMap();
    response.put(XFormsProcessor.SUBMISSION_RESPONSE_STREAM, new ByteArrayInputStream(stream.toByteArray()));
    return response;
}

From source file:de.uzk.hki.da.metadata.MetadataStructure.java

private Element addEdmProvidedCHOtoEdm(PreservationSystem preservationSystem, String id, Document edmDoc,
        Element rootElement) {/*w w  w .j ava 2s. c om*/
    String cho_identifier = preservationSystem.getUrisCho() + "/" + id;
    Element providedCHO = edmDoc.createElement(C.EDM_PROVIDED_CHO);
    Attr rdfAbout = edmDoc.createAttribute("rdf:about");
    rdfAbout.setValue(cho_identifier);
    providedCHO.setAttributeNode(rdfAbout);
    rootElement.appendChild(providedCHO);

    return providedCHO;
}

From source file:com.dinochiesa.edgecallouts.EditXmlNode.java

private void replace(NodeList nodes, Node newNode, short newNodeType) {
    Node currentNode = nodes.item(0);
    switch (newNodeType) {
    case Node.ATTRIBUTE_NODE:
        Element parent = ((Attr) currentNode).getOwnerElement();
        parent.removeAttributeNode((Attr) currentNode);
        parent.setAttributeNode((Attr) newNode);
        break;/*ww w. j  a  v  a  2 s.  c o  m*/
    case Node.ELEMENT_NODE:
        currentNode.getParentNode().replaceChild(newNode, currentNode);
        break;
    case Node.TEXT_NODE:
        currentNode.setNodeValue(newNode.getNodeValue());
        break;
    }
}

From source file:de.uzk.hki.da.metadata.MetadataStructure.java

private Element addOreAggregationToEdm(PreservationSystem preservationSystem, String id, Document edmDoc,
        Element rootElement) {//  w  w w  . j av  a2s.  c  om
    String aggr_identifier = preservationSystem.getUrisAggr() + "/" + id;
    Element aggregation = edmDoc.createElement(C.EDM_ORE_AGGREGATION);
    Attr rdfAbout = edmDoc.createAttribute("rdf:about");
    rdfAbout.setValue(aggr_identifier);
    aggregation.setAttributeNode(rdfAbout);
    rootElement.appendChild(aggregation);

    Element aggregatedCHO = edmDoc.createElement(C.EDM_AGGREGATED_CHO);
    Attr rdfAboutACho = edmDoc.createAttribute("rdf:resource");
    rdfAboutACho.setValue(preservationSystem.getUrisCho() + "/" + id);
    aggregatedCHO.setAttributeNode(rdfAboutACho);
    aggregation.appendChild(aggregatedCHO);

    return aggregation;
}

From source file:de.elbe5.base.data.XmlData.java

public void addAttribute(Element node, String key, String value) {
    Attr attr = doc.createAttribute(key);
    attr.setNodeValue(value == null ? "" : value);
    node.setAttributeNode(attr);
}

From source file:ch.entwine.weblounge.bridge.oaipmh.util.XmlGen.java

/**
 * Append node <code>n</code> to element <code>e</code> respecting different
 * node types like attributes and elements.
 *//*  w  ww.  ja va 2  s . com*/
private void appendTo(Element e, Node n) {
    Node toAppend = ObjectUtils.equals(n.getOwnerDocument(), document) ? n : document.importNode(n, true);
    if (toAppend instanceof Attr) {
        e.setAttributeNode((Attr) toAppend);
    } else {
        e.appendChild(toAppend);
    }
}

From source file:clus.statistic.RegressionStat.java

@Override
public Element getPredictElement(Document doc) {
    Element stats = doc.createElement("RegressionStat");
    NumberFormat fr = ClusFormat.SIX_AFTER_DOT;
    Attr examples = doc.createAttribute("examples");
    examples.setValue(fr.format(m_SumWeight));

    stats.setAttributeNode(examples);
    for (int i = 0; i < m_NbAttrs; i++) {
        Element attr = doc.createElement("Target");
        Attr name = doc.createAttribute("name");
        name.setValue(m_Attrs[i].getName());
        attr.setAttributeNode(name);/* www .ja  va 2s.  co  m*/

        double tot = getSumWeights(i);
        if (tot == 0)
            attr.setTextContent("?");
        else
            attr.setTextContent(fr.format(getSumValues(i) / tot));

        stats.appendChild(attr);
    }
    return stats;
}

From source file:de.interactive_instruments.ShapeChange.Target.Metadata.ApplicationSchemaMetadata.java

/** Add attribute to an element */
protected void addAttribute(Element e, String name, String value) {
    Attr att = document.createAttribute(name);
    att.setValue(value);// w  ww .ja v a2  s  .c  o  m
    e.setAttributeNode(att);
}

From source file:it.unibas.spicy.persistence.xml.operators.ExportXSD.java

private void processRoot(INode root, Document document) {
    Element schema = document.createElementNS(XSD_NS, PREFIX + "schema");
    document.appendChild(schema);//from w  w  w. j a va 2 s  .c  o m
    Attr elementFormDefault = document.createAttribute("elementFormDefault");
    elementFormDefault.setValue("qualified");
    schema.setAttributeNode(elementFormDefault);
}