James,
Thanks for this -- those test cases should help me track it down faster 
next time.

The docs (a.xml and b.xml) are different -- agreed. The problem is that 
when I add the missing 'deltaxml="foo"' namespace to a.xml, so that 
"asXML()" shows them to be identical, the NodeComparator rejects them as 
different. The reason seems to be that
element.addNamespace ("deltaxml", "foo");
adds a new Namespace object to the *content* of the element -- as iterated 
over by a nodeIterator. This extra object is not present in the content of 
"x" in the second doc.

So: given a.xml:
<top><x/></top>

and b.xml:
<top xmlns:deltaxml="foo"><x/></top>

how do I munge a.xml so that NodeComparator considers the docs to be equal? 
I've had to hack together a quick fix (not using NodeComparator, ignoring 
namespaces) for now, but I need a longer-term solution. Any ideas?

Thanks a lot,
Thomas.


At 14:24 27/11/2001 +0000, James Strachan wrote:
>I guess the NodeComparator could ignore duplicate namespace declarations,
>though technically the XML object models are different, so I think the
>documents are different.
>
>BTW if ever anyone is having problems comparing documents that they think
>are equal but the NodeComparator decides that they are different, you might
>find the following useful.
>
>In dom4j/test/src/org/dom4j/AbstractTestCase.java is-a JUnit TestCase and is
>an abstract base class for dom4j test cases. It contains a whole bunch of
>useful assertion helper methods for testing documents, nodes and fragments
>being equal. The nice thing is that you get useful messages telling you
>exactly why they are different, so its pretty easy to track down.
>
>e.g.
>
>public MyTest extends AbstractTestCase {
>     ...
>     public void testSomething() {
>         Document doc1 = ...;
>         Document doc2 = ...;
>
>         assertDocumentsEqual( doc1, doc2 );
>     }
>}
>
>James
>----- Original Message -----
>From: "Thomas Nichols" <[EMAIL PROTECTED]>
>To: <[EMAIL PROTECTED]>
>Sent: Tuesday, November 27, 2001 12:50 PM
>Subject: Re: [dom4j-user] Changing document NS after parsing
>
>
> > Very bad form, replying to my own post - but I've tracked it down.
> >
> > I was calling
> > el.addNamespace ("deltaxml", "foo");
> > for the "x" element in the first doc. The second doc's "x" element already
> > has a NS decl, inherited from "top".
> > A nodeIterator() on the first "x" (in a.xml, after addNamespace()) finds 1
> > content item - a Namespace. For the second doc, b.xml, a nodeIterator on
> > its "x" element gives 0 content items.
> >
> > So... although asML() gives identical results:
> > <top xmlns:deltaxml="foo"><x/></top>
> >
> > the two docs are different because one has a Namespace "node" and the
>other
> > doesn't.
> >
> > Is this as expected? Workarounds, anyone?
> > Thanks,
> > Thomas.
> >
> >
> >
> > At 21:14 26/11/2001 +0000, Thomas Nichols wrote:
> > >Good Day,
> > >
> > >I'm using the NodeComparator in a regression-test setup - comparing
> > >expected with actual results. I get differences if doc B has a namespace
> > >declaration that isn't present in A (or vice versa) - even if it's
>unused.
> > >This is important because a "deltaxml" namespace may (but need not be)
> > >declared in these docs -- so for these files, a 'deltaxml="foo"' present
> > >in one but not the other is an ignorable difference.
> > >
> > >For example:
> > >$cat a.xml
> > ><?xml version="1.0" encoding="UTF-8" standalone="yes"?>
> > ><top><x/></top>
> > >
> > >$cat b.xml
> > ><?xml version="1.0" encoding="UTF-8" standalone="yes"?>
> > ><top xmlns:deltaxml="foo"><x/></top>
> > >
> > >Calling  topElement.addNamespace ("deltaxml", "foo");  doesn't fix the
> > >problem - the NodeComparator still says they're different.
> > >
> > >I guessed that this is because the "x" child element in b.xml gets a
> > >namespace decl for "foo" when it's initially parsed, and that adding the
> > >decl to the "top" element in a.xml does _not_ add it to the child "x"
> > >element. However, even recursive addNamespace() calls on all children do
> > >not give a tree that matches - even though asXML() gives an apparently
> > >identical tree.
> > >
> > >Is there any way to change the declared namespaces for an Element and all
> > >its children? What about Attributes? I don't understand from
> > >NodeComparator.java why this approach isn't working.
> > >
> > >======
> > >
> > >Notes: Attribute has a getNamespace(), but no addNamespace() --
> > >asymmetrical with Element. Attribute has a setNamespace(Namespace) which
> > >is missing from Element.
> > >I am probably confusing the _declared_ namespaces for a node -- as
> > >returned by Attribute.getDeclaredNamespaces(), can't see this for Element
> > >-- with the namespace of a particular node -- e.g.
><xhtml:head>...</xhtml:head>
> > >
> > >Adding 'xmlns:deltaxml="foo"' (unsurprisingly) makes NodeComparator
>happy.
> > >
> > >[ Aside: What causes asXML to output "<x></x>" instead of "<x/>" ? ]
> > >
> > >
> > >Any advice or direction warmly received,
> > >
> > >Thanks,
> > >Thomas.
> > >
> > >PS: Isn't dom4j just wonderful?
> > >
> > >
> > >_______________________________________________
> > >dom4j-user mailing list
> > >[EMAIL PROTECTED]
> > >https://lists.sourceforge.net/lists/listinfo/dom4j-user
> >
> >
> > _______________________________________________
> > dom4j-user mailing list
> > [EMAIL PROTECTED]
> > https://lists.sourceforge.net/lists/listinfo/dom4j-user
> >
>
>
>_________________________________________________________
>Do You Yahoo!?
>Get your free @yahoo.com address at http://mail.yahoo.com


_______________________________________________
dom4j-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/dom4j-user

Reply via email to