當前位置: 首頁>>代碼示例>>Java>>正文


Java Attr.setNodeValue方法代碼示例

本文整理匯總了Java中org.w3c.dom.Attr.setNodeValue方法的典型用法代碼示例。如果您正苦於以下問題:Java Attr.setNodeValue方法的具體用法?Java Attr.setNodeValue怎麽用?Java Attr.setNodeValue使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.w3c.dom.Attr的用法示例。


在下文中一共展示了Attr.setNodeValue方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: extractFeatureAtts

import org.w3c.dom.Attr; //導入方法依賴的package包/類
public static ArrayList<Node> extractFeatureAtts(Fs features, Document D,
        String prefix) {
    ArrayList<Node> atts = new ArrayList<Node>();
    for (String key : features.getKeys()) {
        String value = features.getFeat(key).toString();
        Attr att = D.createAttribute(prefix + key);
        att.setNodeValue(value);
        atts.add(att);
    }
    return atts;
}
 
開發者ID:spetitjean,項目名稱:TuLiPA-frames,代碼行數:12,代碼來源:ViewTreeBuilder.java

示例2: setAttribute

import org.w3c.dom.Attr; //導入方法依賴的package包/類
public void setAttribute(String name, String value) throws DOMException {
    Attr attribute = getAttributeNode(name);
    if (attribute == null) {
        attribute = mOwnerDocument.createAttribute(name);
    }
    attribute.setNodeValue(value);
    mAttributes.setNamedItem(attribute);
}
 
開發者ID:XecureIT,項目名稱:PeSanKita-android,代碼行數:9,代碼來源:ElementImpl.java

示例3: startElement

import org.w3c.dom.Attr; //導入方法依賴的package包/類
/**
 * Adds a new child {@link org.w3c.dom.Element Element} to the current
 * node.
 * 
 * @param namespaceURI the namespace URI
 * @param localName the local name
 * @param qName the qualified (prefixed) name
 * @param atts the list of attributes
 * @throws SAXException if the DOM implementation throws an exception
 */
@Override
public void startElement(String namespaceURI, String localName,
                         String qName, Attributes atts)
    throws SAXException {

    try {
        Node previousTop = top;
        if ((localName == null) || (localName.length() == 0)) { 
            top = doc.createElement(qName);
        } else {
            top = doc.createElementNS(namespaceURI, localName);
        }
        for (int i = 0; i < atts.getLength(); i++) {
            Attr attr = null;
            if ((atts.getLocalName(i) == null) ||
                (atts.getLocalName(i).length() == 0)) {
                attr = doc.createAttribute(atts.getQName(i));
                attr.setNodeValue(atts.getValue(i));
                ((Element)top).setAttributeNode(attr);
            } else {
                attr = doc.createAttributeNS(atts.getURI(i),
                                             atts.getLocalName(i));
                attr.setNodeValue(atts.getValue(i));
                ((Element)top).setAttributeNodeNS(attr);
            }
        }
        previousTop.appendChild(top);
        depth++;
    } catch (DOMException e) {
        throw new SAXException(e.getMessage(), e);
    }

}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:44,代碼來源:NodeCreateRule.java

示例4: startElement

import org.w3c.dom.Attr; //導入方法依賴的package包/類
/**
 * Adds a new child {@link org.w3c.dom.Element Element} to the current
 * node.
 * 
 * @param namespaceURI the namespace URI
 * @param localName the local name
 * @param qName the qualified (prefixed) name
 * @param atts the list of attributes
 * @throws SAXException if the DOM implementation throws an exception
 */
public void startElement(String namespaceURI, String localName,
                         String qName, Attributes atts)
    throws SAXException {

    try {
        Node previousTop = top;
        if ((localName == null) || (localName.length() == 0)) { 
            top = doc.createElement(qName);
        } else {
            top = doc.createElementNS(namespaceURI, localName);
        }
        for (int i = 0; i < atts.getLength(); i++) {
            Attr attr = null;
            if ((atts.getLocalName(i) == null) ||
                (atts.getLocalName(i).length() == 0)) {
                attr = doc.createAttribute(atts.getQName(i));
                attr.setNodeValue(atts.getValue(i));
                ((Element)top).setAttributeNode(attr);
            } else {
                attr = doc.createAttributeNS(atts.getURI(i),
                                             atts.getLocalName(i));
                attr.setNodeValue(atts.getValue(i));
                ((Element)top).setAttributeNodeNS(attr);
            }
        }
        previousTop.appendChild(top);
        depth++;
    } catch (DOMException e) {
        throw new SAXException(e.getMessage());
    }

}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:43,代碼來源:NodeCreateRule.java

示例5: setAttribute

import org.w3c.dom.Attr; //導入方法依賴的package包/類
/**
* Add a new name/value pair, or replace the value of the existing
* attribute having that name.
*
* Note: this method supports only the simplest kind of Attribute,
* one whose value is a string contained in a single Text node.
* If you want to assert a more complex value (which XML permits,
* though HTML doesn't), see setAttributeNode().
*
* The attribute is created with specified=true, meaning it's an
* explicit value rather than inherited from the DTD as a default.
* Again, setAttributeNode can be used to achieve other results.
*
* @throws DOMException(INVALID_NAME_ERR) if the name is not acceptable.
* (Attribute factory will do that test for us.)
*
* @throws DOMException(NO_MODIFICATION_ALLOWED_ERR) if the node is
* readonly.
*/
   public void setAttribute(String name, String value) {

           if (ownerDocument.errorChecking && isReadOnly()) {
                   String msg =
                           DOMMessageFormatter.formatMessage(
                                   DOMMessageFormatter.DOM_DOMAIN,
                                   "NO_MODIFICATION_ALLOWED_ERR",
                                   null);
                   throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, msg);
           }

           if (needsSyncData()) {
                   synchronizeData();
           }

           Attr newAttr = getAttributeNode(name);
           if (newAttr == null) {
                   newAttr = getOwnerDocument().createAttribute(name);

                   if (attributes == null) {
                           attributes = new AttributeMap(this, null);
                   }

                   newAttr.setNodeValue(value);
                   attributes.setNamedItem(newAttr);
           }
           else {
                   newAttr.setNodeValue(value);
           }

   }
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:51,代碼來源:ElementImpl.java

示例6: setAttribute

import org.w3c.dom.Attr; //導入方法依賴的package包/類
/**
 * Add a new name/value pair, or replace the value of the existing attribute
 * having that name.
 *
 * Note: this method supports only the simplest kind of Attribute, one whose
 * value is a string contained in a single Text node. If you want to assert
 * a more complex value (which XML permits, though HTML doesn't), see
 * setAttributeNode().
 *
 * The attribute is created with specified=true, meaning it's an explicit
 * value rather than inherited from the DTD as a default. Again,
 * setAttributeNode can be used to achieve other results.
 *
 * @throws DOMException(INVALID_NAME_ERR) if the name is not acceptable.
 * (Attribute factory will do that test for us.)
 *
 * @throws DOMException(NO_MODIFICATION_ALLOWED_ERR) if the node is
 * readonly.
 */
public void setAttribute(String name, String value) {

    if (ownerDocument.errorChecking && isReadOnly()) {
        String msg
                = DOMMessageFormatter.formatMessage(
                        DOMMessageFormatter.DOM_DOMAIN,
                        "NO_MODIFICATION_ALLOWED_ERR",
                        null);
        throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, msg);
    }

    if (needsSyncData()) {
        synchronizeData();
    }

    Attr newAttr = getAttributeNode(name);
    if (newAttr == null) {
        newAttr = getOwnerDocument().createAttribute(name);

        if (attributes == null) {
            attributes = new AttributeMap(this, null);
        }

        newAttr.setNodeValue(value);
        attributes.setNamedItem(newAttr);
    } else {
        newAttr.setNodeValue(value);
    }

}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:50,代碼來源:ElementImpl.java

示例7: startElement

import org.w3c.dom.Attr; //導入方法依賴的package包/類
/**
 * Adds a new child {@link org.w3c.dom.Element Element} to the current
 * node.
 * 
 * @param namespaceURI
 *            the namespace URI
 * @param localName
 *            the local name
 * @param qName
 *            the qualified (prefixed) name
 * @param atts
 *            the list of attributes
 * @throws SAXException
 *             if the DOM implementation throws an exception
 */
@Override
public void startElement(String namespaceURI, String localName, String qName, Attributes atts)
		throws SAXException {

	try {
		Node previousTop = top;
		if ((localName == null) || (localName.length() == 0)) {
			top = doc.createElement(qName);
		} else {
			top = doc.createElementNS(namespaceURI, localName);
		}
		for (int i = 0; i < atts.getLength(); i++) {
			Attr attr = null;
			if ((atts.getLocalName(i) == null) || (atts.getLocalName(i).length() == 0)) {
				attr = doc.createAttribute(atts.getQName(i));
				attr.setNodeValue(atts.getValue(i));
				((Element) top).setAttributeNode(attr);
			} else {
				attr = doc.createAttributeNS(atts.getURI(i), atts.getLocalName(i));
				attr.setNodeValue(atts.getValue(i));
				((Element) top).setAttributeNodeNS(attr);
			}
		}
		previousTop.appendChild(top);
		depth++;
	} catch (DOMException e) {
		throw new SAXException(e.getMessage(), e);
	}

}
 
開發者ID:how2j,項目名稱:lazycat,代碼行數:46,代碼來源:NodeCreateRule.java

示例8: createIsInheritedAttr

import org.w3c.dom.Attr; //導入方法依賴的package包/類
private static Attr createIsInheritedAttr(Document document, DatabaseObject dbo, DatabaseObject dboParent) {
	Attr attr = document.createAttribute("isInherited");
	attr.setNodeValue(Boolean.toString(!dboParent.toString().equals(dbo.getParent().toString())));
	return attr;
}
 
開發者ID:convertigo,項目名稱:convertigo-engine,代碼行數:6,代碼來源:GetChildren.java

示例9: duplicateNode

import org.w3c.dom.Attr; //導入方法依賴的package包/類
/**
 * Helper method used by {@link #findAlternateToolsXml(InputStream)} to duplicate a node
 * and attach it to the given root in the new document.
 */
private Element duplicateNode(Element newRootNode, Element oldNode,
        String namespaceUri, String prefix) {
    // The implementation here is more or less equivalent to
    //
    //    newRoot.appendChild(newDoc.importNode(oldNode, deep=true))
    //
    // except we can't just use importNode() since we need to deal with the fact
    // that the old document is not namespace-aware yet the new one is.

    Document newDoc = newRootNode.getOwnerDocument();
    Element newNode = null;

    String nodeName = oldNode.getNodeName();
    int pos = nodeName.indexOf(':');
    if (pos > 0 && pos < nodeName.length() - 1) {
        nodeName = nodeName.substring(pos + 1);
        newNode = newDoc.createElementNS(namespaceUri, nodeName);
        newNode.setPrefix(prefix);
    } else {
        newNode = newDoc.createElement(nodeName);
    }

    newRootNode.appendChild(newNode);

    // Merge in all the attributes
    NamedNodeMap attrs = oldNode.getAttributes();
    for (int i = 0; i < attrs.getLength(); i++) {
        Attr attr = (Attr) attrs.item(i);
        Attr newAttr = null;

        String attrName = attr.getNodeName();
        pos = attrName.indexOf(':');
        if (pos > 0 && pos < attrName.length() - 1) {
            attrName = attrName.substring(pos + 1);
            newAttr = newDoc.createAttributeNS(namespaceUri, attrName);
            newAttr.setPrefix(prefix);
        } else {
            newAttr = newDoc.createAttribute(attrName);
        }

        newAttr.setNodeValue(attr.getNodeValue());

        if (pos > 0) {
            newNode.getAttributes().setNamedItemNS(newAttr);
        } else {
            newNode.getAttributes().setNamedItem(newAttr);
        }
    }

    // Merge all child elements and texts
    for (Node child = oldNode.getFirstChild(); child != null; child = child.getNextSibling()) {
        if (child.getNodeType() == Node.ELEMENT_NODE) {
            duplicateNode(newNode, (Element) child, namespaceUri, prefix);

        } else if (child.getNodeType() == Node.TEXT_NODE) {
            Text newText = newDoc.createTextNode(child.getNodeValue());
            newNode.appendChild(newText);
        }
    }

    return newNode;
}
 
開發者ID:tranleduy2000,項目名稱:javaide,代碼行數:67,代碼來源:SdkRepoSource.java

示例10: extractFqcns

import org.w3c.dom.Attr; //導入方法依賴的package包/類
/**
 * Extracts the fully qualified class names from the manifest and uses the
 * prefix notation relative to the manifest package. This basically reverses
 * the effects of {@link #expandFqcns(Document)}, though of course it may
 * also remove prefixes which were inlined in the original documents.
 *
 * @param doc the document in which to extract the FQCNs.
 */
private void extractFqcns(Document doc) {
    // Find the package attribute of the manifest.
    String pkg = null;
    Element manifest = findFirstElement(doc, "/manifest");
    if (manifest != null) {
        pkg = manifest.getAttribute("package");
    }

    if (pkg == null || pkg.length() == 0) {
        return;
    }

    int pkgLength = pkg.length();
    for (String elementAttr : sClassAttributes) {
        String[] names = elementAttr.split("/");
        if (names.length != 2) {
            continue;
        }
        String elemName = names[0];
        String attrName = names[1];
        NodeList elements = doc.getElementsByTagName(elemName);
        for (int i = 0; i < elements.getLength(); i++) {
            Node elem = elements.item(i);
            if (elem instanceof Element) {
                Attr attr = ((Element) elem).getAttributeNodeNS(NS_URI, attrName);
                if (attr != null) {
                    String value = attr.getNodeValue();

                    // We know it's a shortened FQCN if it starts with a dot
                    // or does not contain any dot.
                    if (value != null && value.length() > pkgLength &&
                            value.startsWith(pkg) && value.charAt(pkgLength) == '.') {
                        value = value.substring(pkgLength);
                        attr.setNodeValue(value);
                    }
                }
            }
        }
    }
}
 
開發者ID:tranleduy2000,項目名稱:javaide,代碼行數:49,代碼來源:ManifestMerger.java


注:本文中的org.w3c.dom.Attr.setNodeValue方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。