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); } }
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); } }
/** 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); } }
/** 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); } }
private Node createAttribute(Document doc, Node currentNode, String axisName) { String attributeName = axisName.substring(1); NamedNodeMap attributesMap = currentNode.getAttributes(); Node attribute = attributesMap.getNamedItem(attributeName); if (attribute==null) { attribute = doc.createAttributeNS("", attributeName); attributesMap.setNamedItem(attribute); } return attribute; }
/** * 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); } } }
public static void mergeElement(Element from, Element to) { // attrs for (int idx = 0; idx < from.getAttributes().getLength(); idx++) { Node node = from.getAttributes().item(idx); to.getAttributes().setNamedItem(node.cloneNode(false)); } // children for (int idx = 0; idx < from.getChildNodes().getLength(); idx++) { Node node = from.getChildNodes().item(idx); if (!Element.class.isInstance(node)) { continue; } to.appendChild(node.cloneNode(true)); } } }
@Override public Node put( String key, Node value ) { map.setNamedItem( value ); return null; }
@Override public void putAll( Map<? extends String, ? extends Node> m ) { for( Node node : m.values() ) { map.setNamedItem( node ); } }
private static void setAttribute(Document xml, Node node, String name, String value) { NamedNodeMap map = node.getAttributes(); Attr attribute = xml.createAttribute(name); attribute.setValue(value); map.setNamedItem(attribute); }
public static void setAttribute(Node node, String attName, String val) { NamedNodeMap attributes = node.getAttributes(); Node attNode = node.getOwnerDocument().createAttributeNS(null, attName); attNode.setNodeValue(val); attributes.setNamedItem(attNode); }
public static void setAttribute(Node node, String attName, String val) { NamedNodeMap attributes = node.getAttributes(); Node attNode = node.getOwnerDocument().createAttributeNS(null, attName); attNode.setNodeValue(val); attributes.setNamedItem(attNode); }
public static void setAttribute(Node node, String attName, String val) { NamedNodeMap attributes=node.getAttributes(); Node attNode=node.getOwnerDocument().createAttribute(attName); attNode.setNodeValue( val ); attributes.setNamedItem(attNode); }
public static void setAttribute(Node node, String attName, String val) { NamedNodeMap attributes=node.getAttributes(); Node attNode=node.getOwnerDocument().createAttribute(attName); attNode.setNodeValue( val ); attributes.setNamedItem(attNode); }
public static void setAttribute(Node node, String attName, String val) { NamedNodeMap attributes = node.getAttributes(); Node attNode = node.getOwnerDocument().createAttributeNS(null, attName); attNode.setNodeValue(val); attributes.setNamedItem(attNode); }
private static Document createEmptyFacesConfigDocument(DOMImplementation domImpl) { Document document = domImpl.createDocument(JAVAEE_XMLNS, "faces-config", null); Attr versionAttribute = document.createAttribute("version"); versionAttribute.setValue("2.2"); document.getDocumentElement() .getAttributes() .setNamedItem(versionAttribute); return document; }
private static void addAttributeToNode(@Nonnull final Node targetNode, @Nonnull final String attributeName, @Nonnull final String attributeValue) { final NamedNodeMap nodeAttributes = targetNode.getAttributes(); final Document doc = targetNode.getOwnerDocument(); final Attr attribute = doc.createAttribute(attributeName); attribute.setNodeValue(attributeValue); nodeAttributes.setNamedItem(attribute); }
@Override @SuppressWarnings("unchecked") public void execute(Rule rule, @SuppressWarnings("rawtypes") RuleContext context, DOMDocument document) { List<Node> nodes = (List<Node>) context.getData(MetaNameMisuseRule.ERRORED_META_NODES); for(Node node : nodes) { final String nameValue = node.getAttributes().getNamedItem("name").getTextContent(); node.getAttributes().removeNamedItem("name"); Node propertyNode = document.getOriginalDocument().createAttribute("property"); propertyNode.setNodeValue(nameValue); node.getAttributes().setNamedItem(propertyNode); } }
public Document handleIncomingOrder(@Body Document xml, @XPath("/order/@customerId") int customerId, @Bean(ref = "guid", method = "generate") int orderId) { Attr attr = xml.createAttribute("orderId"); attr.setValue("" + orderId); Node node = xml.getElementsByTagName("order").item(0); node.getAttributes().setNamedItem(attr); return xml; }
/** * Sets the specified attribute. * @param node the attribute */ @JsxFunction public void setNamedItem(final Node node) { attributes_.setNamedItem(node.getDomNodeOrDie()); }