本文整理了Java中org.w3c.dom.Element.setAttributeNode()
方法的一些代码示例,展示了Element.setAttributeNode()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Element.setAttributeNode()
方法的具体详情如下:
包路径:org.w3c.dom.Element
类名称:Element
方法名:setAttributeNode
[英]Adds a new attribute node. If an attribute with that name ( nodeName
) is already present in the element, it is replaced by the new one. Replacing an attribute node by itself has no effect.
To add a new attribute node with a qualified name and namespace URI, use the setAttributeNodeNS
method.
[中]添加新的属性节点。如果元素中已存在具有该名称(nodeName
)的属性,则该属性将被新属性替换。单独替换属性节点没有效果。
要添加具有限定名称和命名空间URI的新属性节点,请使用setAttributeNodeNS
方法。
代码示例来源:origin: 4thline/cling
protected Element writeBodyElement(Document d) {
Element envelopeElement = d.createElementNS(Constants.SOAP_NS_ENVELOPE, "s:Envelope");
Attr encodingStyleAttr = d.createAttributeNS(Constants.SOAP_NS_ENVELOPE, "s:encodingStyle");
encodingStyleAttr.setValue(Constants.SOAP_URI_ENCODING_STYLE);
envelopeElement.setAttributeNode(encodingStyleAttr);
d.appendChild(envelopeElement);
Element bodyElement = d.createElementNS(Constants.SOAP_NS_ENVELOPE, "s:Body");
envelopeElement.appendChild(bodyElement);
return bodyElement;
}
代码示例来源:origin: commons-digester/commons-digester
attr = doc.createAttribute(atts.getQName(i));
attr.setNodeValue(atts.getValue(i));
((Element)top).setAttributeNode(attr);
} else {
attr = doc.createAttributeNS(atts.getURI(i),
代码示例来源: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: robovm/robovm
element.setAttributeNode(attr);
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
@Override
public Node[] merge(List<Node> nodeList1, List<Node> nodeList2, List<Node> exhaustedNodes) {
if (CollectionUtils.isEmpty(nodeList1) || CollectionUtils.isEmpty(nodeList2)) {
return null;
}
Node node1 = nodeList1.get(0);
Node node2 = nodeList2.get(0);
NamedNodeMap attributes2 = node2.getAttributes();
Comparator<Object> nameCompare = new Comparator<Object>() {
@Override
public int compare(Object arg0, Object arg1) {
return ((Node) arg0).getNodeName().compareTo(((Node) arg1).getNodeName());
}
};
Node[] tempNodes = {};
tempNodes = exhaustedNodes.toArray(tempNodes);
Arrays.sort(tempNodes, nameCompare);
int length = attributes2.getLength();
for (int j = 0; j < length; j++) {
Node temp = attributes2.item(j);
int pos = Arrays.binarySearch(tempNodes, temp, nameCompare);
if (pos < 0) {
Attr clone = (Attr) temp.cloneNode(true);
((Element) node1).setAttributeNode((Attr) node1.getOwnerDocument().importNode(clone, true));
}
}
return null;
}
代码示例来源:origin: stackoverflow.com
staff.setAttributeNode(attr);
代码示例来源:origin: spring-projects/spring-framework
@Test
public void marshalDOMResult() throws Exception {
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
documentBuilderFactory.setNamespaceAware(true);
DocumentBuilder builder = documentBuilderFactory.newDocumentBuilder();
Document result = builder.newDocument();
DOMResult domResult = new DOMResult(result);
marshaller.marshal(flights, domResult);
Document expected = builder.newDocument();
Element flightsElement = expected.createElementNS("http://samples.springframework.org/flight", "tns:flights");
Attr namespace = expected.createAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:tns");
namespace.setNodeValue("http://samples.springframework.org/flight");
flightsElement.setAttributeNode(namespace);
expected.appendChild(flightsElement);
Element flightElement = expected.createElementNS("http://samples.springframework.org/flight", "tns:flight");
flightsElement.appendChild(flightElement);
Element numberElement = expected.createElementNS("http://samples.springframework.org/flight", "tns:number");
flightElement.appendChild(numberElement);
Text text = expected.createTextNode("42");
numberElement.appendChild(text);
assertThat("Marshaller writes invalid DOMResult", result, isSimilarTo(expected));
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void marshalEmptyDOMResult() throws Exception {
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
documentBuilderFactory.setNamespaceAware(true);
DocumentBuilder builder = documentBuilderFactory.newDocumentBuilder();
DOMResult domResult = new DOMResult();
marshaller.marshal(flights, domResult);
assertTrue("DOMResult does not contain a Document", domResult.getNode() instanceof Document);
Document result = (Document) domResult.getNode();
Document expected = builder.newDocument();
Element flightsElement = expected.createElementNS("http://samples.springframework.org/flight", "tns:flights");
Attr namespace = expected.createAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:tns");
namespace.setNodeValue("http://samples.springframework.org/flight");
flightsElement.setAttributeNode(namespace);
expected.appendChild(flightsElement);
Element flightElement = expected.createElementNS("http://samples.springframework.org/flight", "tns:flight");
flightsElement.appendChild(flightElement);
Element numberElement = expected.createElementNS("http://samples.springframework.org/flight", "tns:number");
flightElement.appendChild(numberElement);
Text text = expected.createTextNode("42");
numberElement.appendChild(text);
assertThat("Marshaller writes invalid DOMResult", result, isSimilarTo(expected));
}
代码示例来源:origin: kiegroup/jbpm
org.w3c.dom.Node n = ((org.w3c.dom.Node) targetElem).getOwnerDocument().importNode(nl.item(i), true);
if (n instanceof Attr) {
((Element) targetElem).setAttributeNode((Attr) n);
} else {
((org.w3c.dom.Node) targetElem).appendChild(n);
代码示例来源: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 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 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: kingthy/TVRemoteIME
protected Element writeBodyElement(Document d) {
Element envelopeElement = d.createElementNS(Constants.SOAP_NS_ENVELOPE, "s:Envelope");
Attr encodingStyleAttr = d.createAttributeNS(Constants.SOAP_NS_ENVELOPE, "s:encodingStyle");
encodingStyleAttr.setValue(Constants.SOAP_URI_ENCODING_STYLE);
envelopeElement.setAttributeNode(encodingStyleAttr);
d.appendChild(envelopeElement);
Element bodyElement = d.createElementNS(Constants.SOAP_NS_ENVELOPE, "s:Body");
envelopeElement.appendChild(bodyElement);
return bodyElement;
}
代码示例来源:origin: stackoverflow.com
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: org.apache.cxf/cxf-api
public void writeAttribute(String local, String value) throws XMLStreamException {
Attr a;
if (local.startsWith("xmlns") && (local.length() == 5 || local.charAt(5) == ':')) {
a = document.createAttributeNS(XML_NS, local);
} else {
a = document.createAttributeNS(null, local);
}
a.setValue(value);
((Element)currentNode).setAttributeNode(a);
}
代码示例来源:origin: apache/cxf
public void writeAttribute(String local, String value) throws XMLStreamException {
Attr a;
if (local.startsWith("xmlns") && (local.length() == 5 || local.charAt(5) == ':')) {
a = document.createAttributeNS(XML_NS, local);
} else {
a = document.createAttributeNS(null, local);
}
a.setValue(value);
((Element)currentNode).setAttributeNode(a);
}
代码示例来源:origin: org.apache.cxf/cxf-core
public void writeAttribute(String local, String value) throws XMLStreamException {
Attr a;
if (local.startsWith("xmlns") && (local.length() == 5 || local.charAt(5) == ':')) {
a = document.createAttributeNS(XML_NS, local);
} else {
a = document.createAttributeNS(null, local);
}
a.setValue(value);
((Element)currentNode).setAttributeNode(a);
}
代码示例来源: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: httpunit/httpunit
public static Element importNode( DocumentImpl document, Element original, boolean deep ) {
Element copy = document.createElementNS( original.getNamespaceURI(), original.getTagName() );
NamedNodeMap attributes = original.getAttributes();
for (int i = 0; i < attributes.getLength(); i++) {
copy.setAttributeNode( (Attr) document.importNode( attributes.item(i), false ) );
}
if (deep) document.importChildren( original, copy );
return copy;
}
内容来源于网络,如有侵权,请联系作者删除!