/** * Returns a NodeSet containing one text node for each token in the first argument. Delimiters are * specified in the second argument. Tokens are determined by a call to <code>StringTokenizer * </code>. If the first argument is an empty string or contains only delimiters, the result will * be an empty NodeSet. * * <p>Contributed to XalanJ1 by <a href="mailto:[email protected]">Benoit Cerrina</a>. * * @param toTokenize The string to be split into text tokens. * @param delims The delimiters to use. * @return a NodeSet as described above. */ public static NodeList tokenize(String toTokenize, String delims) { Document doc = DocumentHolder.m_doc; StringTokenizer lTokenizer = new StringTokenizer(toTokenize, delims); NodeSet resultSet = new NodeSet(); synchronized (doc) { while (lTokenizer.hasMoreTokens()) { resultSet.addNode(doc.createTextNode(lTokenizer.nextToken())); } } return resultSet; }
/** * Returns true if both node-sets contain the same set of nodes. * * @param nl1 NodeList for first node-set * @param nl2 NodeList for second node-set * @return true if nl1 and nl2 contain exactly the same set of nodes. */ public static boolean hasSameNodes(NodeList nl1, NodeList nl2) { NodeSet ns1 = new NodeSet(nl1); NodeSet ns2 = new NodeSet(nl2); if (ns1.getLength() != ns2.getLength()) return false; for (int i = 0; i < ns1.getLength(); i++) { Node n = ns1.elementAt(i); if (!ns2.contains(n)) return false; } return true; }