Menu

setIgnoreWhitespace(true) and namespace

Elias Ross
2007-08-22
2013-03-03
  • Elias Ross

    Elias Ross - 2007-08-22

    This test fails, though I expect it would succeed. I filed a bug on this.

        public void testIgnoreWhitespace2() throws Exception {
            String control =
                "<env:Envelope xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'>" +
                "\r\n   <env:Header/>" +
                "\r\n   </env:Envelope>";
            String test =
                "<env:Envelope xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'>" +
                "<env:Header/>" +
                "</env:Envelope>";       
            XMLUnit.setIgnoreWhitespace(true);
            try {
                Diff diff = XMLUnit.compareXML(control, test);
                System.out.println(test);
                System.out.println(control);
                System.out.println(new DetailedDiff(diff));
                assertEquals("Should be identical", true,
                        new Diff(control, test).identical());
            } finally {
                XMLUnit.setIgnoreWhitespace(false);
            }
        }
    Output:
    <env:Envelope xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'><env:Header/></env:Envelope>
    <env:Envelope xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'>
       <env:Header/>
       </env:Envelope>
    org.custommonkey.xmlunit.DetailedDiff
    [different] Expected number of child nodes '3' but was '1' - comparing <env:Envelope...> at /Envelope[1] to <env:Envelope...> at /Envelope[1]

    [different] Expected presence of child node '#text' but was 'null' - comparing <env:Envelope ...>
       </env:Envelope> at /Envelope[1] to  at /Envelope[1]/Header[1]

    [not identical] Expected sequence of child nodes '1' but was '0' - comparing <env:Header...> at /Envelope[1]/Header[1] to <env:Header...> at /Envelope[1]/Header[1]

    [different] Expected presence of child node '#text' but was 'null' - comparing <env:Envelope ...>
       </env:Envelope> at /Envelope[1]/Header[1] to  at /Envelope[1]/Header[1]

    Feel free to use my test as your unit test.

     
    • Stefan Bodewig

      Stefan Bodewig - 2007-08-23

      It's a bit hard to decide whether I should follow up here or in the bug report 8-)

      Anyway, I've added your test http://xmlunit.svn.sourceforge.net/viewvc/xmlunit?view=rev&revision=230 and it passes for me.

       
    • Elias Ross

      Elias Ross - 2007-08-23

      Sorry ... tried the test you checked in and it too fails.

      I reopened the bug, because it fails on two different versions of JDK 1.5. Perhaps it's because I'm on Linux as well, I'm not sure. It does pass on JDK 1.6. I can probably come up with a patch for you if you'd like.

      Since you didn't have any open issues I wasn't sure if the bug DB or the forum was the correct place. :-)

       
    • Elias Ross

      Elias Ross - 2007-08-23

      The problem seems to be due to this:
      http://issues.apache.org/jira/browse/XALANJ-2230
      and
      http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6413803

      I suppose I could upgrade my JDK 1.5 to release 12 from 11 but I don't think it would work. Is it possible for you to create some sort of work-around?

       
      • Stefan Bodewig

        Stefan Bodewig - 2007-08-24

        Yep, I think this is the culprit.

        Let's keep the discussion in one place - and I suggest to use the bugreport since people are more likely to search the bug database than the forums (my guess).

         

Log in to post a comment.