Ignoreing node

Help
dume
2009-12-09
2013-03-03
  • dume

    dume - 2009-12-09

    Hi guys

    I know folks have asked that a few times now but I still don't get it…
    How can I prevent xmlunit from checking a defined node?
    I know that I probably have to write my own DifferenceListener but how?
    I mean how does the DifferenceListener work?
    I found this very helpful code- snippet:

        public class IgnoreNamedElementsDifferenceListener implements DifferenceListener {
        private Set<String> blackList = new HashSet<String>();

        public IgnoreNamedElementsDifferenceListener(String … elementNames) {
            for (String name : elementNames) {
                blackList.add(name);
            }
        }

        public int differenceFound(Difference difference) {
            if (difference.getId() == DifferenceConstants.TEXT_VALUE_ID) {
                if (blackList.contains(difference.getControlNodeDetail().getNode().getParentNode().getNodeName())) {
                    return DifferenceListener.RETURN_IGNORE_DIFFERENCE_NODES_IDENTICAL;
                }
            }

            return DifferenceListener.RETURN_ACCEPT_DIFFERENCE;
        }

        public void skippedComparison(Node node, Node node1) {

        }
    }

    But it seems that it doesn't work (my test class was running over 10 minutes after I implemented this code, then I stopped the test)..

    I really love this project but this functionality is missing…

    greetz from switzerland
    dume

     
  • dume

    dume - 2009-12-09

    Update:

    Firstly: I know it's called "ignoring" ;)

    Then: I now have implemented a DifferenceListener by myself:

        private class IgnoreCreateDateDifferenceListener implements DifferenceListener {

            public int differenceFound(Difference arg0) {
                String nodeName =
                        arg0.getControlNodeDetail().getNode().getParentNode().getNodeName();
                if(nodeName.equals("createDate"))
                {
                    return DifferenceListener.RETURN_IGNORE_DIFFERENCE_NODES_SIMILAR;
                }
                return DifferenceListener.RETURN_ACCEPT_DIFFERENCE;
            }

            public void skippedComparison(Node arg0, Node arg1) {
            }
        }

    I think I don't have to say that I just want xmlunit to ignore the createDate- Node. When I debug my test I can see the differenceFound- method returns

    `RETURN_IGNORE_DIFFERENCE_NODES_SIMILAR`

    . So everything should be fine. BUT after that xmlunit throws an OutOfMemoryError- exception! The weird thing is: This doesn't happen if I don't override the DifferenceListener…

    Additional infos:

    xmlunit- version: 1.3

    jdk: 1.6

     
  • dume

    dume - 2009-12-10

    Update 2:

    After I built xmlunit by myself and debugged through the code of xmlunit I recognized the problem is not xmlunit. It looks like my xml file is too big and xmlunit can't handle that. So why did it work with the default DifferenceListener? That's quite simple: xmlunit found a difference in the xml- file so it raised an exception and aborted the search for other differences before it used too much of the memory…

    So the only question left is: How do I compare two xml- files which are bigger then normal xmls? (at about 100-200 mb with 4 gigs of memory in my machine)

    greetz dume

     
  • Stefan Bodewig

    Stefan Bodewig - 2009-12-11

    XMLUnit uses DOM internally - and it would be pretty difficult to implement things like ElementQualifier on top of SAX or StaX.

    As a consequence it can only work if the DOM trees of both documents fits into memory.

    Apart from making sure your Java VM gets enough memory the only thing you could try is using a different XML parser in the hope that it uses less memory, but I wouldn't expect to see a very different result.

    I'm sorry, but there isn't really much you can do.

     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks