List of usage examples for org.w3c.dom Attr getName
public String getName();
From source file:org.structr.web.entity.dom.DOMElement.java
@Override public Attr removeAttributeNode(final Attr attr) throws DOMException { // save existing attribute node Attr attribute = getAttributeNode(attr.getName()); // set value//from w w w . j a v a2 s . c om setAttribute(attr.getName(), null); return attribute; }
From source file:org.structr.web.entity.dom.DOMElement.java
@Override public Node doImport(final Page newPage) throws DOMException { DOMElement newElement = (DOMElement) newPage.createElement(getTagName()); // copy attributes for (String _name : getHtmlAttributeNames()) { Attr attr = getAttributeNode(_name); if (attr.getSpecified()) { newElement.setAttribute(attr.getName(), attr.getValue()); }//ww w.ja va 2 s . c om } return newElement; }
From source file:org.tizzit.util.XercesHelper.java
public static Node renameNode(Node nde, String strName) { if (!strName.equals(nde.getNodeName())) { Document xdoc = nde.getOwnerDocument(); Element retnode = xdoc.createElement(strName); NodeList nl = nde.getChildNodes(); for (int i = 0; i < nl.getLength(); i++) { retnode.appendChild(nl.item(i).cloneNode(true)); }/*from w w w .j a v a 2 s. c om*/ NamedNodeMap al = nde.getAttributes(); for (int i = 0; i < al.getLength(); i++) { Attr attr = (Attr) al.item(i); retnode.setAttribute(attr.getName(), attr.getValue()); } return retnode; } return nde; }
From source file:org.wso2.carbon.humantask.core.engine.runtime.xpath.XPathExpressionRuntime.java
private Element replaceElement(Element lval, Element src) { Document doc = lval.getOwnerDocument(); NodeList nl = src.getChildNodes(); for (int i = 0; i < nl.getLength(); ++i) { lval.appendChild(doc.importNode(nl.item(i), true)); }/* w ww . j a v a 2 s. c o m*/ NamedNodeMap attrs = src.getAttributes(); for (int i = 0; i < attrs.getLength(); ++i) { Attr attr = (Attr) attrs.item(i); if (!attr.getName().startsWith("xmlns")) { lval.setAttributeNodeNS((Attr) doc.importNode(attrs.item(i), true)); // Case of qualified attribute values, we're forced to add corresponding namespace declaration manually int colonIdx = attr.getValue().indexOf(":"); if (colonIdx > 0) { String prefix = attr.getValue().substring(0, colonIdx); String attrValNs = src.lookupPrefix(prefix); if (attrValNs != null) { lval.setAttributeNS(DOMUtils.NS_URI_XMLNS, "xmlns:" + prefix, attrValNs); } } } } return lval; }
From source file:org.wso2.developerstudio.eclipse.esb.impl.ModelObjectImpl.java
/** * Extracts any namespace definitions ("xmlns:prefix=uri") declared on the * element.//from w w w . ja v a 2s . c o m * * @param element * {@link Element} to be examined. * @return mapping of namespace prefixes to URIs. */ protected Map<String, String> extractNamespaces(Element element) { Map<String, String> namespaces = new HashMap<String, String>(); NamedNodeMap attributes = element.getAttributes(); for (int i = 0; i < attributes.getLength(); i++) { Attr attr = (Attr) attributes.item(i); if (attr.getName().startsWith("xmlns:")) { namespaces.put(attr.getName().substring("xmlns:".length()), attr.getValue()); } } return namespaces; }
From source file:tkwatch.Utilities.java
/** * Recursively travels through a DOM tree. Adapted from Vohra and Vohra, * <i>Pro XML Development with Java Technology</i>, p. 47. This was used * during development and is not called by <strong>TKWatch+</strong>. * Retained for completeness.//from w ww . j a v a2 s. c o m * * @param previousNode * @param visitNode */ public static void visitNode(Element previousNode, Element visitNode) { if (previousNode != null) { System.out.println("Element " + previousNode.getTagName() + " has element:"); } System.out.println("Element Name: " + visitNode.getTagName()); if (visitNode.hasAttributes()) { System.out.println("Element " + visitNode.getTagName() + " has attributes: "); NamedNodeMap attributes = visitNode.getAttributes(); for (int j = 0; j < attributes.getLength(); j++) { Attr attribute = (Attr) (attributes.item(j)); System.out.println("Attribute:" + attribute.getName() + " with value " + attribute.getValue()); } } // Obtain a NodeList of nodes in an Element node. NodeList nodeList = visitNode.getChildNodes(); for (int i = 0; i < nodeList.getLength(); i++) { Node node = nodeList.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { Element element = (Element) node; visitNode(visitNode, element); } else if (node.getNodeType() == Node.TEXT_NODE) { String str = node.getNodeValue().trim(); if (str.length() > 0) { System.out.println("Element Text: " + str); } } } }
From source file:util.XmlWriter.java
private String writeAttributes(Element element) { StringBuilder attributeString = new StringBuilder(); NamedNodeMap attributeMap = element.getAttributes(); int length = attributeMap.getLength(); for (int i = 0; i < length; i++) { Attr attributeNode = (Attr) attributeMap.item(i); String name = attributeNode.getName(); String value = attributeNode.getValue(); attributeString.append(" ").append(name).append("=\"").append(value).append("\""); }//from w w w . j a v a 2s .c o m return attributeString.toString(); }
From source file:VASSAL.build.module.GlobalOptions.java
public void build(Element e) { if (e == null) return;//from w w w .j a v a2 s . com final NamedNodeMap nnm = e.getAttributes(); for (int i = 0; i < nnm.getLength(); ++i) { final Attr att = (Attr) nnm.item(i); setAttribute(att.getName(), att.getValue()); } for (Node n = e.getFirstChild(); n != null; n = n.getNextSibling()) { if (n.getNodeType() == Node.ELEMENT_NODE) { final Element element = (Element) n; if ("option".equals(element.getTagName())) { //$NON-NLS-1$ final String optionName = element.getAttribute("name"); //$NON-NLS-1$ final String value = Builder.getText(element); optionInitialValues.put(optionName, value); // Update the Configurer value if it is already registered final Configurer config = optionConfigurers.get(optionName); if (config != null) { config.setValue(value); } } else { try { final Buildable b = Builder.create(element); b.addTo(this); add(b); } catch (IllegalBuildException ex) { ErrorDialog.bug(ex); } } } } }
From source file:yax.test.XmlTest.java
static void dumpnode(Node node, int depth, StringBuilder buf) throws Exception { switch (node.getNodeType()) { case DOCUMENT_NODE: Node root = ((Document) node).getDocumentElement(); buf.append("<?xml version=\"1.0\"?>\n"); buf.append("<!DOCTYPE>\n"); dumpnode(root, 0, buf);//www . j ava2s .co m break; case ELEMENT_NODE: Element enode = (Element) node; buf.append(String.format("%s<%s", indent(depth), enode.getTagName())); NamedNodeMap attrs = enode.getAttributes(); if (attrs != null) { for (int i = 0; i < attrs.getLength(); i++) { Attr attr = (Attr) attrs.item(i); buf.append(String.format(" %s=\"%s\"", attr.getName(), attr.getValue())); } } buf.append(">\n"); NodeList children = enode.getChildNodes(); if (children != null) { for (int i = 0; i < children.getLength(); i++) { Node child = children.item(i); dumpnode(child, depth + 1, buf); } } buf.append(String.format("%s</%s>", indent(depth), enode.getTagName())); break; case TEXT_NODE: buf.append(String.format("%s|%s|", indent(depth), ((Text) node).getData())); break; default: String typename = node.getNodeName(); throw new Exception("dumpnode: unexpected node type: " + typename); } }