本文整理汇总了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;
}
示例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);
}
示例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);
}
}
示例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());
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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;
}
示例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;
}
示例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);
}
}
}
}
}
}