Example usage for org.w3c.dom Attr setValue

List of usage examples for org.w3c.dom Attr setValue

Introduction

In this page you can find the example usage for org.w3c.dom Attr setValue.

Prototype

public void setValue(String value) throws DOMException;

Source Link

Document

On retrieval, the value of the attribute is returned as a string.

Usage

From source file:forge.quest.io.QuestDataIO.java

@SuppressWarnings("unchecked")
private static <T> T readAsset(final XStream xs, final Document doc, final String tagName,
        final Class<T> clasz) {
    final NodeList nn = doc.getElementsByTagName(tagName);
    final Node n = nn.item(0);

    final Attr att = doc.createAttribute("resolves-to");
    att.setValue(clasz.getCanonicalName());
    n.getAttributes().setNamedItem(att);

    final String xmlData = XmlUtil.nodeToString(n);
    return (T) xs.fromXML(xmlData);
}

From source file:BuildXml.java

public Node createContactNode(Document document) {

    // create FirstName and LastName elements
    Element firstName = document.createElement("FirstName");
    Element lastName = document.createElement("LastName");

    firstName.appendChild(document.createTextNode("First Name"));
    lastName.appendChild(document.createTextNode("Last Name"));

    // create contact element
    Element contact = document.createElement("contact");

    // create attribute
    Attr genderAttribute = document.createAttribute("gender");
    genderAttribute.setValue("F");

    // append attribute to contact element
    contact.setAttributeNode(genderAttribute);
    contact.appendChild(firstName);/*  www  .  java  2 s  .c om*/
    contact.appendChild(lastName);

    return contact;
}

From source file:com.marklogic.dom.AttrImpl.java

protected Node cloneNode(Document doc, boolean deep) {
    Attr attr = doc.createAttributeNS(getNamespaceURI(), getLocalName());
    attr.setValue(getValue());
    attr.setPrefix(getPrefix());//www  .  j a va2  s  . c o m
    return attr;
}

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);//from w  w w  .ja v  a 2  s. c om
    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);
        attr.setTextContent(fr.format(getMean(i)));
        stats.appendChild(attr);
    }
    return stats;
}

From source file:com.amalto.core.history.accessor.AttributeAccessor.java

public void set(String value) {
    Node namedItem = getAttribute();
    if (namedItem == null) {
        throw new IllegalStateException("Attribute '" + attributeName + "' does not exist."); //$NON-NLS-1$ //$NON-NLS-2$
    }/*from w  w  w.  j  a  va  2 s  .  c o  m*/
    if (!(namedItem instanceof Attr)) {
        throw new IllegalStateException(
                "Expected a " + Attr.class.getName() + " instance but got a " + namedItem.getClass().getName()); //$NON-NLS-1$ //$NON-NLS-2$
    }

    Attr attribute = (Attr) namedItem;
    attribute.setValue(value);
}

From source file:com.amalto.core.history.accessor.AttributeAccessor.java

public void createAndSet(String value) {
    // Ensure everything is created in parent nodes.
    parent.create();//w  w w. j a  va 2s .c om

    Document domDocument = document.asDOM();
    Node parentNode = parent.getNode();
    Attr attribute = createAttribute(parentNode, domDocument);
    attribute.setValue(value);
}

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  va 2 s  .  com*/
            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:gov.medicaid.services.impl.FileNetServiceBean.java

/**
 * Creates the XML./*  w  w w . j  a  v  a2  s. c  o  m*/
 * 
 * @param outFile
 *            the output file handler
 * @param attributes
 *            the content
 * @throws PortalServiceException
 *             if any error occurs
 */
private void createXML(File outFile, Map<String, String> attributes) throws PortalServiceException {
    try {
        DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder docBuilder = docFactory.newDocumentBuilder();

        // root elements
        Document doc = docBuilder.newDocument();
        Element rootElement = doc.createElement("Document");
        doc.appendChild(rootElement);
        for (String key : attributes.keySet()) {
            Element indexVal = doc.createElement("Indexvalue");
            Attr attr = doc.createAttribute("name");
            attr.setValue(key);
            indexVal.setAttributeNode(attr);
            if (attributes.get(key) != null) {
                indexVal.appendChild(doc.createTextNode(attributes.get(key)));
            }
            rootElement.appendChild(indexVal);
        }
        // write the content into xml file
        TransformerFactory transformerFactory = TransformerFactory.newInstance();
        Transformer transformer = transformerFactory.newTransformer();
        DOMSource source = new DOMSource(doc);
        StreamResult result = new StreamResult(outFile);

        transformer.transform(source, result);

    } catch (ParserConfigurationException e) {
        throw new PortalServiceException("Failed to create FileNet xml", e);
    } catch (TransformerException e) {
        throw new PortalServiceException("Failed to create FileNet xml", e);
    }

}

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

private Element addEdmProvidedCHOtoEdm(PreservationSystem preservationSystem, String id, Document edmDoc,
        Element rootElement) {//from  w w  w.j a  v a 2  s . com
    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:de.uzk.hki.da.metadata.MetadataStructure.java

private Element addOreAggregationToEdm(PreservationSystem preservationSystem, String id, Document edmDoc,
        Element rootElement) {/*from   w ww.  j av  a 2s.co  m*/
    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;
}