Package org.castor.xmlctf.xmldiff.xml.nodes

Examples of org.castor.xmlctf.xmldiff.xml.nodes.XMLNode


     *
     * @return the BaseNode
     * @throws java.io.IOException if any exception occurs during parsing
     */
    public XMLNode read() throws java.io.IOException {
        XMLNode node = null;

        try {
            InputSource source = new InputSource();
            source.setSystemId(_location);
            source.setCharacterStream(new FileReader(_file));
View Full Code Here


     *         indicating the number of differences.
     * @throws java.io.IOException an this occurs while reading
     */
    public int compare() throws java.io.IOException {
        XMLFileReader reader1 = new XMLFileReader(_file1);
        XMLNode node1 = reader1.read();

        XMLFileReader reader2 = new XMLFileReader(_file2);
        XMLNode node2 = reader2.read();

        return compareNodes(node1, node2);
    }
View Full Code Here

        Iterator i1 = node1.getChildIterator();
        Iterator i2 = node2.getChildIterator();

        // Skip all ignorable whitespace and compare with strict order
        if (i1.hasNext() && i2.hasNext()) {
            XMLNode child1 = (XMLNode) i1.next();
            XMLNode child2 = (XMLNode) i2.next();
            while (child1 != null && child2 != null) {
                if (nodeIsIgnorableText(child1)) {
                    if (!i1.hasNext()) {
                        break;
                    }
                    child1 = (XMLNode) i1.next();
                    continue;
                }
                if (nodeIsIgnorableText(child2)) {
                    if (!i2.hasNext()) {
                        break;
                    }
                    child2 = (XMLNode) i2.next();
                    continue;
                }

                diffCount += compareNodes(child1, child2);

                if (!i1.hasNext() || !i2.hasNext()) {
                    break;
                }

                child1 = (XMLNode) i1.next();
                child2 = (XMLNode) i2.next();
            }
        }

        // If we have excess nodes for root1, complain about missing elements
        while (i1.hasNext()) {
            XMLNode child1 = (XMLNode) i1.next();
            if (!nodeIsIgnorableText(child1)) {
                if (_print) {
                    printLocationInfo(child1, null);
                    _pw.println("- ");
                }
                ++diffCount;
            }
        }

        // If we have excess nodes for root2, complain about extra elements
        while (i2.hasNext()) {
            XMLNode child2 = (XMLNode) i2.next();
            if (!nodeIsIgnorableText(child2)) {
                if (_print) {
                    printLocationInfo(child2, null);
                    _pw.println("- ");
                }
View Full Code Here

        int diffCount = 0;

        final List used = new LinkedList();

        for (Iterator i1 = node1.getChildIterator(); i1.hasNext(); ) {
            XMLNode child1 = (XMLNode) i1.next();
            // Ignore whitespace
            // If we find an exact match, continue with the next node in the list
            if (nodeIsIgnorableText(child1) || foundExactMatch(node2, child1, used)) {
                continue;
            }

            // Check for the best match and use it to count diffs & complain
            if (_print) {
                diffCount += closestMatchDifference(node2, child1, used);
            } else {
                diffCount++;
            }
        }

        // Complain about all children of node2 that are not used and not ignorable whitespace
        for (Iterator i2 = node2.getChildIterator(); i2.hasNext(); ) {
            XMLNode child2 = (XMLNode) i2.next();
            if (!nodeIsIgnorableText(child2) && !used.contains(child2)) {
                if (_print) {
                    _pw.println("Extra child node: " + child2.getNodeLocation());
                }
                ++diffCount;
            }
        }
View Full Code Here

        boolean previousPrint = _print;

        _print = false; // Suppress printing when we are "just looking"
        boolean found = false;
        for (Iterator i2 = parent.getChildIterator(); i2.hasNext(); ) {
            XMLNode child2 = (XMLNode) i2.next();
            if (!usedList.contains(child2) && compareNodes(target, child2) == 0) {
                usedList.add(child2);
                found = true;
                break;
            }
View Full Code Here

     * @return the difference count
     */
    private int closestMatchDifference(final Element parent, final XMLNode target,
                                       final List usedList) {
        for (Iterator i2 = parent.getChildIterator(); i2.hasNext(); ) {
            XMLNode child2 = (XMLNode) i2.next();
            if (!usedList.contains(child2) && hasSameType(target, child2)
                && hasSameName(target, child2)) {
                usedList.add(child2);
                return compareNodes(target, child2);
            }
View Full Code Here

TOP

Related Classes of org.castor.xmlctf.xmldiff.xml.nodes.XMLNode

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.