List of usage examples for org.w3c.dom Node isEqualNode
public boolean isEqualNode(Node arg);
From source file:Main.java
/** * This method will compare the attributes of a given src element with the attributes of a given dest element. * Both must contain the same attributes, but you can specify a String array of attribute names whose values * are ignored. Both elements must have the ignore attributes, their contents can be different and they will * still be considered equal./* ww w . ja v a 2 s .c o m*/ * @param src - the src element whose attributes are to be compared * @param dest - the dest element whose attributes are to be compared * @param ignore - the string array of attributes whose values are to be ignored during the compare. * @return true if the attributes of both nodes meet the criteria of being equal, false otherwise. */ private static boolean compareAttributes(Element src, Element dest, String[] ignore) { NamedNodeMap srcAttrs = src.getAttributes(); if (srcAttrs.getLength() != dest.getAttributes().getLength()) return false; for (int ctr = 0; ctr < srcAttrs.getLength(); ctr++) { Node srcAttr = srcAttrs.item(ctr); String name = srcAttr.getNodeName(); if (Arrays.binarySearch(ignore, name) < 0) { Node destAttr = dest.getAttributeNode(name); if (destAttr == null || !srcAttr.isEqualNode(destAttr)) { return false; } } } return true; }
From source file:com.igormaznitsa.upom.UPomModel.java
private static void duplicatedSiblingJanitor(final Log log, final Node node, final List<String> path) { if (node == null) { return;/*from w w w . j a va 2s . c o m*/ } insideElementJanitor(log, node, path); Node sibling = nextSiblingElement(node); while (sibling != null) { insideElementJanitor(log, sibling, path); sibling = nextSiblingElement(sibling); } sibling = nextSiblingElement(node); while (sibling != null) { if (node.isEqualNode(sibling)) { path.add(node.getNodeName()); final Node deleting = sibling; sibling = nextSiblingElement(sibling); if (log != null) { log.warn("Removing duplicated element : " + pathToString(path)); } deleting.getParentNode().removeChild(deleting); path.remove(path.size() - 1); } else { sibling = nextSiblingElement(sibling); } } }
From source file:com.fujitsu.dc.test.utils.DavResourceUtils.java
/** * XML????????????????./*from w w w. j av a 2 s.c o m*/ * @param res PROPFIND? * @param tagName ????? * @param expectedNode ? */ public static void assertEqualsNodeInResXml(TResponse res, String tagName, Node expectedNode) { Document propfind = res.bodyAsXml(); NodeList list; list = propfind.getElementsByTagName(tagName); for (int i = 0; i < list.getLength(); i++) { Node item = list.item(i); if (item.isEqualNode(expectedNode)) { return; } } // ??????????? fail(); }
From source file:org.eclipse.thym.core.plugin.test.InstallActionsTest.java
@Test public void testXMLConfigFileActionInstall() throws FileNotFoundException, IOException, CoreException, SAXException, ParserConfigurationException, XPathExpressionException { final File target = TestUtils.createTempFile("AndroidManifest.xml"); final String xml = "<config-file target=\"AndroidManifest.xml\" parent=\"/manifest\">" + "<uses-permission android:name=\"android.permission.BLUETOOTH\" />" + "<uses-permission android:name=\"android.permission.BLUETOOTH_ADMIN\" />" + "</config-file >"; final String parentExpression = "/manifest"; XMLConfigFileAction action = new XMLConfigFileAction(target, parentExpression, xml); action.install();/* w w w . java2s . co m*/ DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder(); Document doc = db.parse(target); Document node = db.parse(new InputSource(new StringReader(xml))); XPath xpath = XPathFactory.newInstance().newXPath(); Node parentNode = (Node) xpath.evaluate(parentExpression, doc, XPathConstants.NODE); assertNotNull(parentNode); NodeList alienChildren = node.getDocumentElement().getChildNodes(); Node[] importedNodes = new Node[alienChildren.getLength()]; for (int i = 0; i < alienChildren.getLength(); i++) { importedNodes[i] = doc.importNode(alienChildren.item(i), true); } NodeList childNodes = parentNode.getChildNodes(); int found = 0; for (int i = 0; i < childNodes.getLength(); i++) { Node current = childNodes.item(i); for (int j = 0; j < importedNodes.length; j++) { if (current.isEqualNode(importedNodes[j])) { found++; } } } assertEquals(importedNodes.length, found); // found all imported nodes }
From source file:org.eclipse.thym.core.plugin.test.InstallActionsTest.java
@Test public void testXMLConfigFileActionUnInstall() throws IOException, CoreException, ParserConfigurationException, SAXException, XPathException { final File target = TestUtils.createTempFile("AndroidManifest.xml"); final String xml = "<config-file target=\"AndroidManifest.xml\" parent=\"/manifest\">" + "<uses-permission android:name=\"android.permission.INTERNET\" />" + "<uses-permission android:name=\"android.permission.RECEIVE_SMS\" />" + "</config-file >"; final String parentExpression = "/manifest"; XMLConfigFileAction action = new XMLConfigFileAction(target, parentExpression, xml); action.unInstall();/* w ww. j a v a2 s. c o m*/ DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder(); Document doc = db.parse(target); Document node = db.parse(new InputSource(new StringReader(xml))); XPath xpath = XPathFactory.newInstance().newXPath(); Node parentNode = (Node) xpath.evaluate(parentExpression, doc, XPathConstants.NODE); assertNotNull(parentNode); NodeList alienChildren = node.getDocumentElement().getChildNodes(); Node[] importedNodes = new Node[alienChildren.getLength()]; for (int i = 0; i < alienChildren.getLength(); i++) { importedNodes[i] = doc.importNode(alienChildren.item(i), true); } NodeList childNodes = parentNode.getChildNodes(); for (int i = 0; i < childNodes.getLength(); i++) { Node current = childNodes.item(i); for (int j = 0; j < importedNodes.length; j++) { assertFalse("Found a node that is not suppposed to be here", current.isEqualNode(importedNodes[j])); } } }
From source file:org.omg.bpmn.miwg.util.xml.diff.AbstractXmlDifferenceListener.java
private Node findCorrespondingNode(Map<Node, Set<String>> map, Node node) { // try to find existing node that corresponds to this one // using Node.isEqual(Node), don't use Node.isSimilar(Node)! for (Node existing : map.keySet()) { if (node.isEqualNode(existing)) { // exchange the new node for the old one to prevent additional // searches for the same node Set<String> attributeNames = map.remove(existing); map.put(node, attributeNames); return node; }/*from ww w .j a va2 s. c o m*/ } return null; }
From source file:org.omg.bpmn.miwg.util.xml.diff.AbstractXmlDifferenceListener.java
private Node findCorrespondingNode(Set<Node> set, Node node) { for (Node existing : set) { if (node.isEqualNode(existing)) { // exchange the new node for the old one to prevent // additional searches for the same node set.remove(existing);//ww w . j a v a 2 s . c om set.add(node); return node; } } return null; }