List of usage examples for org.w3c.dom.traversal NodeFilter acceptNode
public short acceptNode(Node n);
TreeWalker or NodeIterator. From source file:Main.java
public String getAttributeValue(Element element, Node attr, NodeFilter attrFilter) { if (attrFilter == null || attrFilter.acceptNode(attr) != -1) { String value = getXMLString(attr.getNodeValue()); String quat = "\""; if (value.indexOf("\"") > 0) { quat = "'"; }/*from w w w .j av a 2 s . c o m*/ return " " + attr.getNodeName() + "=" + quat + value + quat; } return ""; }
From source file:de.betterform.xml.dom.DOMUtil.java
/** * copies all attributes from one Element to another * * @param from - the Element which the source attributes * @param to - the target Element for the Attributes * @param filter - a NodeFilter to apply during copy *///w w w . j av a 2 s . co m public static void copyAttributes(Element from, Element to, NodeFilter filter) { if ((from != null) && (to != null)) { NamedNodeMap map = from.getAttributes(); /* if filter is null use our own default filter, which accepts everything (this saves us from always check if filter is null */ if (filter == null) { filter = new NodeFilter() { public short acceptNode(Node n) { return NodeFilter.FILTER_ACCEPT; } }; } if (map != null) { int len = map.getLength(); for (int i = 0; i < len; i++) { Node attr = map.item(i); if (attr.getNodeType() == Node.ATTRIBUTE_NODE) { if (filter.acceptNode(attr) == NodeFilter.FILTER_ACCEPT) { to.setAttributeNS(attr.getNamespaceURI(), attr.getNodeName(), attr.getNodeValue()); } } } } } }