本文整理了Java中org.w3c.dom.Document.createAttribute()
方法的一些代码示例,展示了Document.createAttribute()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Document.createAttribute()
方法的具体详情如下:
包路径:org.w3c.dom.Document
类名称:Document
方法名:createAttribute
[英]Creates an Attr
of the given name. Note that the Attr
instance can then be set on an Element
using the setAttributeNode
method.
To create an attribute with a qualified name and namespace URI, use the createAttributeNS
method.
[中]创建给定名称的Attr
。请注意,然后可以使用setAttributeNode
方法在Element
上设置Attr
实例。
要创建具有限定名称和命名空间URI的属性,请使用createAttributeNS
方法。
代码示例来源:origin: plutext/docx4j
/**
* {@inheritDoc}
*
* @throws DOMException If thrown by method invoked on the underlying DOM document
*/
public void attribute(String name, String value) throws DOMException {
if (!this.isNude)
throw new IllegalArgumentException("Cannot write attribute: too late!");
Attr att = this.document.createAttribute(name);
att.setValue(value);
this.currentElement.appendChild(att);
}
代码示例来源:origin: commons-digester/commons-digester
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);
代码示例来源:origin: libgdx/libgdx
/** If the child node or attribute doesn't exist, it is created. Usage example: Node property =
* getFirstChildByAttrValue(properties, "property", "name"); */
private static Node getFirstChildByNameAttrValue (Node node, String childName, String attr, String value) {
NodeList childNodes = node.getChildNodes();
for (int i = 0; i < childNodes.getLength(); i++) {
if (childNodes.item(i).getNodeName().equals(childName)) {
NamedNodeMap attributes = childNodes.item(i).getAttributes();
Node attribute = attributes.getNamedItem(attr);
if (attribute.getNodeValue().equals(value)) return childNodes.item(i);
}
}
Node newNode = node.getOwnerDocument().createElement(childName);
NamedNodeMap attributes = newNode.getAttributes();
Attr nodeAttr = node.getOwnerDocument().createAttribute(attr);
nodeAttr.setNodeValue(value);
attributes.setNamedItem(nodeAttr);
if (childNodes.item(0) != null) {
return node.insertBefore(newNode, childNodes.item(0));
} else {
return node.appendChild(newNode);
}
}
代码示例来源:origin: libgdx/libgdx
private static void setProperty (Document doc, Node parent, String name, String value) {
Node properties = getFirstChildNodeByName(parent, "properties");
Node property = getFirstChildByNameAttrValue(properties, "property", "name", name);
NamedNodeMap attributes = property.getAttributes();
Node valueNode = attributes.getNamedItem("value");
if (valueNode == null) {
valueNode = doc.createAttribute("value");
valueNode.setNodeValue(value);
attributes.setNamedItem(valueNode);
} else {
valueNode.setNodeValue(value);
}
}
代码示例来源:origin: libgdx/libgdx
private static void setProperty (Document doc, Node parent, String name, String value) {
Node properties = getFirstChildNodeByName(parent, "properties");
Node property = getFirstChildByNameAttrValue(properties, "property", "name", name);
NamedNodeMap attributes = property.getAttributes();
Node valueNode = attributes.getNamedItem("value");
if (valueNode == null) {
valueNode = doc.createAttribute("value");
valueNode.setNodeValue(value);
attributes.setNamedItem(valueNode);
} else {
valueNode.setNodeValue(value);
}
}
代码示例来源:origin: libgdx/libgdx
/** If the child node or attribute doesn't exist, it is created. Usage example: Node property =
* getFirstChildByAttrValue(properties, "property", "name"); */
private static Node getFirstChildByNameAttrValue (Node node, String childName, String attr, String value) {
NodeList childNodes = node.getChildNodes();
for (int i = 0; i < childNodes.getLength(); i++) {
if (childNodes.item(i).getNodeName().equals(childName)) {
NamedNodeMap attributes = childNodes.item(i).getAttributes();
Node attribute = attributes.getNamedItem(attr);
if (attribute.getNodeValue().equals(value)) return childNodes.item(i);
}
}
Node newNode = node.getOwnerDocument().createElement(childName);
NamedNodeMap attributes = newNode.getAttributes();
Attr nodeAttr = node.getOwnerDocument().createAttribute(attr);
nodeAttr.setNodeValue(value);
attributes.setNamedItem(nodeAttr);
if (childNodes.item(0) != null) {
return node.insertBefore(newNode, childNodes.item(0));
} else {
return node.appendChild(newNode);
}
}
代码示例来源:origin: groovy/groovy-core
public static void putAt(Element self, String property, Object value) {
if (property.startsWith("@")) {
String attributeName = property.substring(1);
Document doc = self.getOwnerDocument();
Attr newAttr = doc.createAttribute(attributeName);
newAttr.setValue(value.toString());
self.setAttributeNode(newAttr);
return;
}
InvokerHelper.setProperty(self, property, value);
}
代码示例来源:origin: org.freemarker/freemarker
private Attr createAttribute(Node node, String name, String value) {
Attr attr = node.getOwnerDocument().createAttribute(name);
attr.setNodeValue(value);
return attr;
}
代码示例来源:origin: loklak/loklak_server
Node delayNode = gceNode.getAttributes().getNamedItem(delayNodeName);
if (delayNode == null) {
delayNode = tree.getOwnerDocument().createAttribute(delayNodeName);
gceNode.appendChild(delayNode);
Node transparencyFlagNode = gceNode.getAttributes().getNamedItem(transparencyFlagNodeName);
if (transparencyFlagNode == null) {
transparencyFlagNode = tree.getOwnerDocument().createAttribute(transparencyFlagNodeName);
gceNode.appendChild(transparencyFlagNode);
Node transparencyIndexNode = gceNode.getAttributes().getNamedItem(transparencyIndexNodeName);
if (transparencyIndexNode == null) {
transparencyIndexNode = tree.getOwnerDocument().createAttribute(transparencyIndexNodeName);
gceNode.appendChild(transparencyIndexNode);
代码示例来源:origin: stackoverflow.com
Attr attr = doc.createAttribute("id");
attr.setValue("1");
staff.setAttributeNode(attr);
代码示例来源:origin: kiegroup/jbpm
@Test
public void testExclusiveSplitXPathAdvanced2() throws Exception {
KieBase kbase = createKnowledgeBase("BPMN2-ExclusiveSplitXPath-advanced-vars-not-signaled.bpmn2");
ksession = createKnowledgeSession(kbase);
ksession.getWorkItemManager().registerWorkItemHandler("Email",
new SystemOutWorkItemHandler());
Map<String, Object> params = new HashMap<String, Object>();
Document doc = DocumentBuilderFactory.newInstance()
.newDocumentBuilder().newDocument();
Element hi = doc.createElement("hi");
Element ho = doc.createElement("ho");
hi.appendChild(ho);
Attr attr = doc.createAttribute("value");
ho.setAttributeNode(attr);
attr.setValue("a");
params.put("x", hi);
params.put("y", "Second");
ProcessInstance processInstance = ksession.startProcess(
"com.sample.test", params);
assertProcessInstanceCompleted(processInstance);
}
代码示例来源:origin: kiegroup/jbpm
@Test
public void testExclusiveSplitXPathAdvanced() throws Exception {
KieBase kbase = createKnowledgeBase("BPMN2-ExclusiveSplitXPath-advanced.bpmn2");
ksession = createKnowledgeSession(kbase);
ksession.getWorkItemManager().registerWorkItemHandler("Email",
new SystemOutWorkItemHandler());
Map<String, Object> params = new HashMap<String, Object>();
Document doc = DocumentBuilderFactory.newInstance()
.newDocumentBuilder().newDocument();
Element hi = doc.createElement("hi");
Element ho = doc.createElement("ho");
hi.appendChild(ho);
Attr attr = doc.createAttribute("value");
ho.setAttributeNode(attr);
attr.setValue("a");
params.put("x", hi);
params.put("y", "Second");
ProcessInstance processInstance = ksession.startProcess(
"com.sample.test", params);
assertProcessInstanceCompleted(processInstance);
}
代码示例来源:origin: kiegroup/jbpm
@Test
public void testExclusiveSplitXPathAdvancedWithVars() throws Exception {
KieBase kbase = createKnowledgeBase("BPMN2-ExclusiveSplitXPath-advanced-with-vars.bpmn2");
ksession = createKnowledgeSession(kbase);
ksession.getWorkItemManager().registerWorkItemHandler("Email",
new SystemOutWorkItemHandler());
Map<String, Object> params = new HashMap<String, Object>();
Document doc = DocumentBuilderFactory.newInstance()
.newDocumentBuilder().newDocument();
Element hi = doc.createElement("hi");
Element ho = doc.createElement("ho");
hi.appendChild(ho);
Attr attr = doc.createAttribute("value");
ho.setAttributeNode(attr);
attr.setValue("a");
params.put("x", hi);
params.put("y", "Second");
ProcessInstance processInstance = ksession.startProcess(
"com.sample.test", params);
assertProcessInstanceCompleted(processInstance);
}
代码示例来源:origin: schemaspy/schemaspy
/**
* Append the specified key/value pair of attributes to the <code>Node</code>.
* @param node Node
* @param name String
* @param value String
*/
public static void appendAttribute(Node node, String name, String value) {
if (value != null) {
Node attribute = node.getOwnerDocument().createAttribute(name);
attribute.setNodeValue(value);
node.getAttributes().setNamedItem(attribute);
}
}
}
代码示例来源:origin: stackoverflow.com
Attr attr = doc.createAttribute("id");
attr.setValue("1");
staff.setAttributeNode(attr);
代码示例来源:origin: openmrs/openmrs-core
private Document buildModuleConfig() throws ParserConfigurationException {
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
Document doc = docBuilder.newDocument();
Element rootElement = doc.createElement("module");
doc.appendChild(rootElement);
Element dwr = doc.createElement("dwr");
dwr.appendChild(doc.createTextNode(""));
rootElement.appendChild(dwr);
Element allow = doc.createElement("allow");
allow.appendChild(doc.createTextNode(""));
dwr.appendChild(allow);
Attr attr = doc.createAttribute("moduleId");
attr.setValue("mymodule");
allow.setAttributeNode(attr);
Element create = doc.createElement("create");
allow.appendChild(create);
return doc;
}
代码示例来源:origin: axis/axis
/**
* @todo: How Axis will maintain the Attribute representation ?
*/
public Attr createAttribute(String name) throws DOMException {
return delegate.createAttribute(name);
}
代码示例来源:origin: org.codehaus.groovy/groovy-xml
public static void putAt(Element self, String property, Object value) {
if (property.startsWith("@")) {
String attributeName = property.substring(1);
Document doc = self.getOwnerDocument();
Attr newAttr = doc.createAttribute(attributeName);
newAttr.setValue(value.toString());
self.setAttributeNode(newAttr);
return;
}
InvokerHelper.setProperty(self, property, value);
}
代码示例来源:origin: org.mule.modules/mule-module-spring-config
public void postProcess(ParserContext unused, BeanAssembler assembler, Element element)
{
Attr attribute = element.getOwnerDocument().createAttribute(name);
attribute.setNodeValue(value);
assembler.extendTarget(attribute);
}
代码示例来源:origin: httpunit/httpunit
public void setAttribute( String name, String value ) throws DOMException {
if (value.equals( getAttribute( name ))) return;
Attr attribute = getOwnerDocument().createAttribute( name );
attribute.setValue( value );
setAttributeNode( attribute );
reportPropertyChanged( name );
}
内容来源于网络,如有侵权,请联系作者删除!