List of usage examples for org.w3c.dom Node getNamespaceURI
public String getNamespaceURI();
null
if it is unspecified (see ). From source file:de.betterform.xml.xforms.model.Model.java
private void loadInlineSchemas(List list) throws XFormsException { String schemaId = null;// w w w.j a v a 2 s. c om try { NodeList children = this.element.getChildNodes(); for (int index = 0; index < children.getLength(); index++) { Node child = children.item(index); if (Node.ELEMENT_NODE == child.getNodeType() && NamespaceConstants.XMLSCHEMA_NS.equals(child.getNamespaceURI())) { Element element = (Element) child; schemaId = element.hasAttributeNS(null, "id") ? element.getAttributeNS(null, "id") : element.getNodeName(); XSModel schema = loadSchema(element); if (schema == null) { throw new NullPointerException("resource not found"); } list.add(schema); } } } catch (Exception e) { throw new XFormsLinkException("could not load inline schema", e, this.target, schemaId); } }
From source file:com.marklogic.dom.NodeImpl.java
protected NodeList getElementsByTagNameNSOrNodeName(String namespaceURI, String name, final boolean nodeName) { final String tagname = name; final String ns = namespaceURI; final Node thisNode = this; return new NodeList() { protected ArrayList<Node> elementList = new ArrayList<Node>(); protected boolean done = false; protected void init() { if (done) return; Stack<Node> childrenStack = new Stack<Node>(); childrenStack.push(thisNode); boolean root = true; while (!childrenStack.isEmpty()) { Node curr = childrenStack.pop(); NodeList children = curr.getChildNodes(); for (int childi = children.getLength() - 1; childi >= 0; childi--) if (children.item(childi).getNodeType() == Node.ELEMENT_NODE) childrenStack.push(children.item(childi)); if (root) { root = false;//from w w w.j a va 2 s . c o m continue; } if (nodeName) { if (curr.getNodeName().equals(tagname) || tagname.equals("*")) elementList.add(curr); } else { // do nothing if only one of the two is null if ("*".equals(ns) && "*".equals(tagname)) { elementList.add(curr); continue; } if (ns != null) { if ((ns.equals("*") || ns.equals(curr.getNamespaceURI())) && (tagname.equals("*") || tagname.equals(curr.getLocalName()))) elementList.add(curr); } else if (tagname.equals("*") || tagname.equals(curr.getLocalName())) elementList.add(curr); } } done = true; } public int getLength() { init(); return elementList.size(); } public Node item(int index) { init(); return (index < getLength()) ? elementList.get(index) : null; } }; }
From source file:DOMWriter.java
private void printInternal(Node node, boolean indentEndMarker) { // is there anything to do? if (node == null) { return;/*from w ww . j ava 2s . c o m*/ } // JBAS-2117 - Don't skip the DOCUMENT_NODE // if (node instanceof Document) node = ((Document)node).getDocumentElement(); if (wroteXMLDeclaration == false && writeXMLDeclaration == true && canonical == false) { out.print("<?xml version='1.0'"); if (charsetName != null) out.print(" encoding='" + charsetName + "'"); out.print("?>"); if (prettyprint) out.println(); wroteXMLDeclaration = true; } int type = node.getNodeType(); boolean hasChildNodes = node.getChildNodes().getLength() > 0; String nodeName = node.getNodeName(); switch (type) { // print document case Node.DOCUMENT_NODE: { NodeList children = node.getChildNodes(); for (int iChild = 0; iChild < children.getLength(); iChild++) { printInternal(children.item(iChild), false); } out.flush(); break; } // print element with attributes case Node.ELEMENT_NODE: { Element element = (Element) node; if (prettyprint) { for (int i = 0; i < prettyIndent; i++) { out.print(' '); } prettyIndent++; } out.print('<'); out.print(nodeName); Map nsMap = new HashMap(); String elPrefix = node.getPrefix(); String elNamespaceURI = node.getNamespaceURI(); if (elPrefix != null) { String nsURI = getNamespaceURI(elPrefix, element, rootNode); nsMap.put(elPrefix, nsURI); } Attr attrs[] = sortAttributes(node.getAttributes()); for (int i = 0; i < attrs.length; i++) { Attr attr = attrs[i]; String atPrefix = attr.getPrefix(); String atName = attr.getNodeName(); String atValue = normalize(attr.getNodeValue(), canonical); if (atName.equals("xmlns")) currentDefaultNamespace = atValue; if (atPrefix != null && !atPrefix.equals("xmlns") && !atPrefix.equals("xml")) { String nsURI = getNamespaceURI(atPrefix, element, rootNode); nsMap.put(atPrefix, nsURI); // xsi:type='ns1:SubType', xsi:type='xsd:string' if (atName.equals(atPrefix + ":type") && atValue.indexOf(":") > 0) { // xsi defined on the envelope if (nsURI == null) nsURI = getNamespaceURI(atPrefix, element, null); if ("http://www.w3.org/2001/XMLSchema-instance".equals(nsURI)) { String typePrefix = atValue.substring(0, atValue.indexOf(":")); String typeURI = getNamespaceURI(typePrefix, element, rootNode); nsMap.put(typePrefix, typeURI); } } } out.print(" " + atName + "='" + atValue + "'"); } // Add namespace declaration for prefixes // that are defined further up the tree if (completeNamespaces) { Iterator itPrefix = nsMap.keySet().iterator(); while (itPrefix.hasNext()) { String prefix = (String) itPrefix.next(); String nsURI = (String) nsMap.get(prefix); if (nsURI == null) { nsURI = getNamespaceURI(prefix, element, null); out.print(" xmlns:" + prefix + "='" + nsURI + "'"); } } } // The SAX ContentHandler will by default not add the namespace declaration // <Hello xmlns='http://somens'>World</Hello> if (elPrefix == null && elNamespaceURI != null) { String defaultNamespace = element.getAttribute("xmlns"); if (defaultNamespace.length() == 0 && !elNamespaceURI.equals(currentDefaultNamespace)) { out.print(" xmlns='" + elNamespaceURI + "'"); currentDefaultNamespace = elNamespaceURI; } } if (hasChildNodes) { out.print('>'); } // Find out if the end marker is indented indentEndMarker = isEndMarkerIndented(node); if (indentEndMarker) { out.print('\n'); } NodeList childNodes = node.getChildNodes(); int len = childNodes.getLength(); for (int i = 0; i < len; i++) { Node childNode = childNodes.item(i); printInternal(childNode, false); } break; } // handle entity reference nodes case Node.ENTITY_REFERENCE_NODE: { if (canonical) { NodeList children = node.getChildNodes(); if (children != null) { int len = children.getLength(); for (int i = 0; i < len; i++) { printInternal(children.item(i), false); } } } else { out.print('&'); out.print(nodeName); out.print(';'); } break; } // print cdata sections case Node.CDATA_SECTION_NODE: { if (canonical) { out.print(normalize(node.getNodeValue(), canonical)); } else { out.print("<![CDATA["); out.print(node.getNodeValue()); out.print("]]>"); } break; } // print text case Node.TEXT_NODE: { String text = normalize(node.getNodeValue(), canonical); if (text.trim().length() > 0) { out.print(text); } else if (prettyprint == false && ignoreWhitespace == false) { out.print(text); } break; } // print processing instruction case Node.PROCESSING_INSTRUCTION_NODE: { out.print("<?"); out.print(nodeName); String data = node.getNodeValue(); if (data != null && data.length() > 0) { out.print(' '); out.print(data); } out.print("?>"); break; } // print comment case Node.COMMENT_NODE: { for (int i = 0; i < prettyIndent; i++) { out.print(' '); } out.print("<!--"); String data = node.getNodeValue(); if (data != null) { out.print(data); } out.print("-->"); if (prettyprint) { out.print('\n'); } break; } } if (type == Node.ELEMENT_NODE) { if (prettyprint) prettyIndent--; if (hasChildNodes == false) { out.print("/>"); } else { if (indentEndMarker) { for (int i = 0; i < prettyIndent; i++) { out.print(' '); } } out.print("</"); out.print(nodeName); out.print('>'); } if (prettyIndent > 0) { out.print('\n'); } } out.flush(); }
From source file:DOMWriter.java
private void printInternal(Node node, boolean indentEndMarker) { // is there anything to do? if (node == null) { return;//w ww . j a v a2s . c o m } // JBAS-2117 - Don't skip the DOCUMENT_NODE // if (node instanceof Document) node = // ((Document)node).getDocumentElement(); if (wroteXMLDeclaration == false && writeXMLDeclaration == true && canonical == false) { out.print("<?xml version='1.0'"); if (charsetName != null) out.print(" encoding='" + charsetName + "'"); out.print("?>"); if (prettyprint) out.println(); wroteXMLDeclaration = true; } int type = node.getNodeType(); boolean hasChildNodes = node.getChildNodes().getLength() > 0; String nodeName = node.getNodeName(); switch (type) { // print document case Node.DOCUMENT_NODE: { NodeList children = node.getChildNodes(); for (int iChild = 0; iChild < children.getLength(); iChild++) { printInternal(children.item(iChild), false); } out.flush(); break; } // print element with attributes case Node.ELEMENT_NODE: { Element element = (Element) node; if (prettyprint) { for (int i = 0; i < prettyIndent; i++) { out.print(' '); } prettyIndent++; } out.print('<'); out.print(nodeName); Map nsMap = new HashMap(); String elPrefix = node.getPrefix(); String elNamespaceURI = node.getNamespaceURI(); if (elPrefix != null) { String nsURI = getNamespaceURI(elPrefix, element, rootNode); nsMap.put(elPrefix, nsURI); } Attr attrs[] = sortAttributes(node.getAttributes()); for (int i = 0; i < attrs.length; i++) { Attr attr = attrs[i]; String atPrefix = attr.getPrefix(); String atName = attr.getNodeName(); String atValue = normalize(attr.getNodeValue(), canonical); if (atName.equals("xmlns")) currentDefaultNamespace = atValue; if (atPrefix != null && !atPrefix.equals("xmlns") && !atPrefix.equals("xml")) { String nsURI = getNamespaceURI(atPrefix, element, rootNode); nsMap.put(atPrefix, nsURI); // xsi:type='ns1:SubType', xsi:type='xsd:string' if (atName.equals(atPrefix + ":type") && atValue.indexOf(":") > 0) { // xsi defined on the envelope if (nsURI == null) nsURI = getNamespaceURI(atPrefix, element, null); if ("http://www.w3.org/2001/XMLSchema-instance".equals(nsURI)) { String typePrefix = atValue.substring(0, atValue.indexOf(":")); String typeURI = getNamespaceURI(typePrefix, element, rootNode); nsMap.put(typePrefix, typeURI); } } } out.print(" " + atName + "='" + atValue + "'"); } // Add namespace declaration for prefixes // that are defined further up the tree if (completeNamespaces) { Iterator itPrefix = nsMap.keySet().iterator(); while (itPrefix.hasNext()) { String prefix = (String) itPrefix.next(); String nsURI = (String) nsMap.get(prefix); if (nsURI == null) { nsURI = getNamespaceURI(prefix, element, null); out.print(" xmlns:" + prefix + "='" + nsURI + "'"); } } } // The SAX ContentHandler will by default not add the namespace // declaration // <Hello xmlns='http://somens'>World</Hello> if (elPrefix == null && elNamespaceURI != null) { String defaultNamespace = element.getAttribute("xmlns"); if (defaultNamespace.length() == 0 && !elNamespaceURI.equals(currentDefaultNamespace)) { out.print(" xmlns='" + elNamespaceURI + "'"); currentDefaultNamespace = elNamespaceURI; } } if (hasChildNodes) { out.print('>'); } // Find out if the end marker is indented indentEndMarker = isEndMarkerIndented(node); if (indentEndMarker) { out.print('\n'); } NodeList childNodes = node.getChildNodes(); int len = childNodes.getLength(); for (int i = 0; i < len; i++) { Node childNode = childNodes.item(i); printInternal(childNode, false); } break; } // handle entity reference nodes case Node.ENTITY_REFERENCE_NODE: { if (canonical) { NodeList children = node.getChildNodes(); if (children != null) { int len = children.getLength(); for (int i = 0; i < len; i++) { printInternal(children.item(i), false); } } } else { out.print('&'); out.print(nodeName); out.print(';'); } break; } // print cdata sections case Node.CDATA_SECTION_NODE: { if (canonical) { out.print(normalize(node.getNodeValue(), canonical)); } else { out.print("<![CDATA["); out.print(node.getNodeValue()); out.print("]]>"); } break; } // print text case Node.TEXT_NODE: { String text = normalize(node.getNodeValue(), canonical); if (text.trim().length() > 0) { out.print(text); } else if (prettyprint == false && ignoreWhitespace == false) { out.print(text); } break; } // print processing instruction case Node.PROCESSING_INSTRUCTION_NODE: { out.print("<?"); out.print(nodeName); String data = node.getNodeValue(); if (data != null && data.length() > 0) { out.print(' '); out.print(data); } out.print("?>"); break; } // print comment case Node.COMMENT_NODE: { for (int i = 0; i < prettyIndent; i++) { out.print(' '); } out.print("<!--"); String data = node.getNodeValue(); if (data != null) { out.print(data); } out.print("-->"); if (prettyprint) { out.print('\n'); } break; } } if (type == Node.ELEMENT_NODE) { if (prettyprint) prettyIndent--; if (hasChildNodes == false) { out.print("/>"); } else { if (indentEndMarker) { for (int i = 0; i < prettyIndent; i++) { out.print(' '); } } out.print("</"); out.print(nodeName); out.print('>'); } if (prettyIndent > 0) { out.print('\n'); } } out.flush(); }
From source file:edu.uams.clara.webapp.xml.processor.impl.DefaultXmlProcessorImpl.java
private synchronized boolean isEqualNode(final Node original, final Node patch) { if (patch == original) { return true; }/*from w w w. j av a2s.co m*/ if (patch.getNodeType() != original.getNodeType()) { return false; } if (original.getNodeName() == null) { if (patch.getNodeName() != null) { return false; } } else if (!original.getNodeName().equals(patch.getNodeName())) { return false; } if (original.getLocalName() == null) { if (patch.getLocalName() != null) { return false; } } else if (!original.getLocalName().equals(patch.getLocalName())) { return false; } if (original.getNamespaceURI() == null) { if (patch.getNamespaceURI() != null) { return false; } } else if (!original.getNamespaceURI().equals(patch.getNamespaceURI())) { return false; } if (original.getPrefix() == null) { if (patch.getPrefix() != null) { return false; } } else if (!original.getPrefix().equals(patch.getPrefix())) { return false; } if (original.getNodeValue() == null) { if (patch.getNodeValue() != null) { return false; } } else if (!original.getNodeValue().equals(patch.getNodeValue())) { return false; } if (original.getTextContent() == null) { if (patch.getTextContent() != null) { return false; } } else if (!original.getTextContent().equals(patch.getTextContent())) { return false; } return true; }
From source file:eu.europa.esig.dss.xades.validation.XAdESSignature.java
private ArchiveTimestampType getArchiveTimestampType(final Node node, final String localName) { if (XPathQueryHolder.XMLE_ARCHIVE_TIME_STAMP_V2.equals(localName)) { return ArchiveTimestampType.XAdES_141_V2; } else if (XPathQueryHolder.XMLE_ARCHIVE_TIME_STAMP.equals(localName)) { final String namespaceURI = node.getNamespaceURI(); if (XAdESNamespaces.XAdES141.equals(namespaceURI)) { return ArchiveTimestampType.XAdES_141; }/* w ww.java 2s . c om*/ } return ArchiveTimestampType.XAdES; }
From source file:com.connexta.arbitro.AbstractPolicy.java
/** * Constructor used by child classes to initialize the shared data from a DOM root node. * * @param root the DOM root of the policy * @param policyPrefix either "Policy" or "PolicySet" * @param combiningName name of the field naming the combining alg * the XACML policy, if null use default factories * @throws ParsingException if the policy is invalid *//*w w w . ja v a 2 s . c om*/ protected AbstractPolicy(Node root, String policyPrefix, String combiningName) throws ParsingException { // get the attributes, all of which are common to Policies NamedNodeMap attrs = root.getAttributes(); try { // get the attribute Id idAttr = new URI(attrs.getNamedItem(policyPrefix + "Id").getNodeValue()); } catch (Exception e) { throw new ParsingException("Error parsing required attribute " + policyPrefix + "Id", e); } // see if there's a version Node versionNode = attrs.getNamedItem("Version"); if (versionNode != null) { version = versionNode.getNodeValue(); } else { // assign the default version version = "1.0"; } // now get the combining algorithm... try { URI algId = new URI(attrs.getNamedItem(combiningName).getNodeValue()); CombiningAlgFactory factory = Balana.getInstance().getCombiningAlgFactory(); combiningAlg = factory.createAlgorithm(algId); } catch (Exception e) { throw new ParsingException("Error parsing combining algorithm" + " in " + policyPrefix, e); } // ...and make sure it's the right kind if (policyPrefix.equals("Policy")) { if (!(combiningAlg instanceof RuleCombiningAlgorithm)) throw new ParsingException("Policy must use a Rule " + "Combining Algorithm"); } else { if (!(combiningAlg instanceof PolicyCombiningAlgorithm)) throw new ParsingException("PolicySet must use a Policy " + "Combining Algorithm"); } // do an initial pass through the elements to pull out the // defaults, if any, so we can setup the meta-data NodeList children = root.getChildNodes(); String xpathVersion = null; for (int i = 0; i < children.getLength(); i++) { Node child = children.item(i); if (DOMHelper.getLocalName(child).equals(policyPrefix + "Defaults")) handleDefaults(child); } // with the defaults read, create the meta-data metaData = new PolicyMetaData(root.getNamespaceURI(), defaultVersion); // now read the remaining policy elements obligationExpressions = new HashSet<AbstractObligation>(); adviceExpressions = new HashSet<AdviceExpression>(); parameters = new ArrayList<CombinerParameter>(); children = root.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node child = children.item(i); String cname = DOMHelper.getLocalName(child); if (cname.equals("Description")) { if (child.hasChildNodes()) { description = child.getFirstChild().getNodeValue(); } } else if (cname.equals("Target")) { target = TargetFactory.getFactory().getTarget(child, metaData); } else if (cname.equals("ObligationExpressions") || cname.equals("Obligations")) { parseObligationExpressions(child); } else if (cname.equals("AdviceExpressions")) { parseAdviceExpressions(child); } else if (cname.equals("CombinerParameters")) { handleParameters(child); } } // finally, make sure the obligations and parameters are immutable obligationExpressions = Collections.unmodifiableSet(obligationExpressions); adviceExpressions = Collections.unmodifiableSet(adviceExpressions); parameters = Collections.unmodifiableList(parameters); }
From source file:de.escidoc.core.test.EscidocTestBase.java
/** * Gets the value of the specified attribute of the root element from the document. * //w w w .j av a2s .c o m * @param document * The document to retrieve the value from. * @param attributeName * The name of the attribute whose value shall be retrieved. * @param namespaceURI * The namespace URI of the attribute. * @return Returns the attribute value. * @throws Exception * If anything fails. */ public static String getRootElementAttributeValueNS(final Document document, final String attributeName, final String namespaceURI) throws Exception { Node root = getRootElement(document); if (root.getNamespaceURI() != null) { // has been parsed namespace aware Node attr = root.getAttributes().getNamedItemNS(namespaceURI, attributeName); assertNotNull("Attribute not found [" + namespaceURI + ":" + attributeName + "]. ", attr); return attr.getTextContent(); } else { // has not been parsed namespace aware. String xPath; if (attributeName.startsWith("@")) { xPath = "/*/" + attributeName; } else { xPath = "/*/@" + attributeName; } assertXmlExists("Attribute not found [" + xPath + "]. ", document, xPath); final Node attr = selectSingleNode(root, xPath); assertNotNull("Attribute not found [" + attributeName + "]. ", attr); String value = attr.getTextContent(); return value; } }
From source file:de.escidoc.core.test.EscidocTestBase.java
/** * Assert XML content is equal.<br/> * <p/>// w w w . j a va2 s . co m * This methods compares the attributes (if any exist) and either recursively compares the child elements (if any * exists) or the text content.<br/> * Therefore, mixed content is NOT supported by this method. * * @param messageIn * The message printed if assertion fails. * @param expected * The expected XML content. * @param toBeAsserted * The XML content to be compared with the expected content. * @throws Exception * If anything fails. */ public static void assertXmlEquals(final String messageIn, final Node expected, final Node toBeAsserted) throws Exception { // Assert both nodes are null or both nodes are not null if (expected == null) { assertNull(messageIn + "Unexpected node. ", toBeAsserted); return; } assertNotNull(messageIn + " Expected node. ", toBeAsserted); if (expected.equals(toBeAsserted)) { return; } String nodeName = getLocalName(expected); String message = messageIn; if (!message.contains("-- Asserting ")) { message = message + "-- Asserting " + nodeName + ". "; } else { message = message + "/" + nodeName; } // assert both nodes are nodes of the same node type // if thedocument container xslt directive than is the nodeName // "#document" is here compared assertEquals(message + " Type of nodes are different", expected.getNodeType(), toBeAsserted.getNodeType()); if (expected.getNodeType() == Node.TEXT_NODE) { assertEquals(message + " Text nodes are different. ", expected.getTextContent().trim(), toBeAsserted.getTextContent().trim()); } // assert attributes NamedNodeMap expectedAttributes = expected.getAttributes(); NamedNodeMap toBeAssertedAttributes = toBeAsserted.getAttributes(); if (expectedAttributes == null) { assertNull(message + " Unexpected attributes. [" + nodeName + "]", toBeAssertedAttributes); } else { assertNotNull(message + " Expected attributes. ", toBeAssertedAttributes); final int expectedNumberAttributes = expectedAttributes.getLength(); for (int i = 0; i < expectedNumberAttributes; i++) { Node expectedAttribute = expectedAttributes.item(i); String expectedAttributeNamespace = expectedAttribute.getNamespaceURI(); Node toBeAssertedAttribute = null; if (expectedAttributeNamespace != null) { final String localName = expectedAttribute.getLocalName(); toBeAssertedAttribute = toBeAssertedAttributes.getNamedItemNS(expectedAttributeNamespace, localName); assertNotNull(message + " Expected attribute " + expectedAttribute.getNodeName(), toBeAssertedAttribute); } else { // not namespace aware parsed. Attributes may have different // prefixes which are now part of their node name. // To compare expected and to be asserted attribute, it is // first it is tried to find the appropriate to be asserted // attribute by the node name. If this fails, xpath // selection is used after extracting the expected // attribute name final String expectedAttributeNodeName = expectedAttribute.getNodeName(); toBeAssertedAttribute = toBeAssertedAttributes.getNamedItem(expectedAttributeNodeName); if (toBeAssertedAttribute == null) { final String attributeName = getLocalName(expectedAttribute); final String attributeXpath = "@" + attributeName; toBeAssertedAttribute = selectSingleNode(toBeAsserted, attributeXpath); } assertNotNull(message + " Expected attribute " + expectedAttributeNodeName, toBeAssertedAttribute); } assertEquals(message + " Attribute value mismatch [" + expectedAttribute.getNodeName() + "] ", expectedAttribute.getTextContent(), toBeAssertedAttribute.getTextContent()); } } // As mixed content (text + child elements) is not supported, // either the child elements or the text content have to be asserted. // Therefore, it is first tried to assert the children. // After that it is checked if children have been found. If this is not // the case, the text content is compared. NodeList expectedChildren = expected.getChildNodes(); NodeList toBeAssertedChildren = toBeAsserted.getChildNodes(); int expectedNumberElementNodes = 0; int toBeAssertedNumberElementNodes = 0; List<Node> previouslyAssertedChildren = new ArrayList<Node>(); for (int i = 0; i < expectedChildren.getLength(); i++) { Node expectedChild = expectedChildren.item(i); if (expectedChild.getNodeType() == Node.ELEMENT_NODE) { expectedNumberElementNodes++; String expectedChildName = getLocalName(expectedChild); String expectedUri = expectedChild.getNamespaceURI(); boolean expectedElementAsserted = false; for (int j = 0; j < toBeAssertedChildren.getLength(); j++) { final Node toBeAssertedChild = toBeAssertedChildren.item(j); // prevent previously asserted children from being // asserted again if (previouslyAssertedChildren.contains(toBeAssertedChild)) { continue; } if (toBeAssertedChild.getNodeType() == Node.ELEMENT_NODE && expectedChildName.equals(getLocalName(toBeAssertedChild)) && (expectedUri == null || expectedUri.equals(toBeAssertedChild.getNamespaceURI()))) { expectedElementAsserted = true; toBeAssertedNumberElementNodes++; assertXmlEquals(message, expectedChild, toBeAssertedChild); // add asserted child to list of asserted children to // prevent it from being asserted again. previouslyAssertedChildren.add(toBeAssertedChild); break; } } if (!expectedElementAsserted) { fail(new StringBuffer(message).append(" Did not found expected corresponding element [") .append(nodeName).append(", ").append(expectedChildName).append(", ").append(i) .append("]").toString()); } } } // check if any element node in toBeAssertedChildren exists // that has not been asserted. In this case, this element node // is unexpected! for (int i = 0; i < toBeAssertedChildren.getLength(); i++) { Node toBeAssertedChild = toBeAssertedChildren.item(i); // prevent previously asserted children from being // asserted again if (previouslyAssertedChildren.contains(toBeAssertedChild)) { continue; } if (toBeAssertedChild.getNodeType() == Node.ELEMENT_NODE) { fail(new StringBuffer(message).append("Found unexpected element node [").append(nodeName) .append(", ").append(getLocalName(toBeAssertedChild)).append(", ").append(i).append("]") .toString()); } } // if no children have been found, text content must be compared if (expectedNumberElementNodes == 0 && toBeAssertedNumberElementNodes == 0) { String expectedContent = expected.getTextContent(); String toBeAssertedContent = toBeAsserted.getTextContent(); assertEquals(message, expectedContent, toBeAssertedContent); } }