normalizing XML namespaces in a DOM document in Java?

Chillout

New Member
I wonder if there is a straightforward way to 'normalize' XML namespace definitions in an XML document represented as a DOM document in Java?the reason I'd need this is to be able to compare two documents, which both use XML namespaces.as XML namespaces can be specified anywhere in the document (in the root element, in any of the elements), etc., two documents that are in effect the same may be significantly different when looked at from a DOM tree perspective. for example, one can have all namespace attributes defined in the root element, while the other can define each namespace at the 'highest' element in the DOM tree hierarchy where the namespace is applicable. In essence these can be the same documents, but when comparing them, say with XmlUnit, one will get comparison issues. to provide two examples:\[code\]<root xmlns:foo="http://foo/"> <e1> <foo:e2>bar</foo:e2> </e1></root>\[/code\]vs:\[code\]<root> <e1 xmlns:foo="http://foo/"> <foo:e2>bar</foo:e2> </e1></root>\[/code\]these documents are in effect the same, but an XML comparison will find them different.I wonder if there is a straightforward / easy way to normalize namespace definitions, say, put them all in the root element?of course one can write such code himself, but if this was available already, that would be way better :)
 
Back
Top