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; }
attr = doc.createAttribute(atts.getQName(i)); attr.setNodeValue(atts.getValue(i)); ((Element)top).setAttributeNode(attr); } else { attr = doc.createAttributeNS(atts.getURI(i),
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); }
element.setAttributeNode(attr);
@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; }
staff.setAttributeNode(attr);
@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)); }
@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)); }
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);
@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); }
@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); }
@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); }
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; }
staff.setAttributeNode(attr);
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; }
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); }
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); }
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); }
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); }
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; }