How to suppress duplicate xmlns attributes in child nodes?

D

david.karr

I'm using JDK 1.4.2 and WebLogic 8.1.4.

I have a situation where we create a blank SOAPMessage object, and
then parse an XML fragment and insert that fragment as the SOAP body.

This works pretty well, but there is one annoyance we see if the root
element of the fragment defines a non-default namespace, and the
elements in the fragment use that prefix.

The problem is that when the SOAPMessage object is marshalled to XML,
that single "xmlns:<prefix>" attribute is present in EVERY element in
the entire XML document. These extra attributes are redundant, as only
the attribute in the root element of the body should be required.
From what I can see, it's hard to say whether the "fault" lies in the
"Document.importNode()" or "SOAPMessage.writeTo()" methods. In any
case, I don't expect fixes to those methods anytime soon.

At one time, I had actually written a custom method that does what
"Document.importNode()" does, and after some minor experimentation, I
realized my custom code can resolve this, but I don't have this option
in my current framework.

We're getting around this for now with a method using JDOM that
regenerates the document using "suppressNamespaces" (I'm not sure
exactly what JDOM method is being used). That sort of fixes the
problem, but any documents that actually use multiple namespaces might
break with this approach.
 
M

Mike Schilling

david.karr said:
I'm using JDK 1.4.2 and WebLogic 8.1.4.

I have a situation where we create a blank SOAPMessage object, and
then parse an XML fragment and insert that fragment as the SOAP body.

This works pretty well, but there is one annoyance we see if the root
element of the fragment defines a non-default namespace, and the
elements in the fragment use that prefix.

The problem is that when the SOAPMessage object is marshalled to XML,
that single "xmlns:<prefix>" attribute is present in EVERY element in
the entire XML document. These extra attributes are redundant, as only
the attribute in the root element of the body should be required.

The first question is whether this really matters. It's suboptimal and
probably annoying, but doesn't affect the functioning of your application,
other than

1. Making the messages less human-readable.
2. Making the process of serializing the message, transmitting it to the
remote service, and parsing it there slightly less efficient

If no human tries to read this message, 1 is unimportant, And unless you
can measure the effects of 2, it's not worth worrying about.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,007
Latest member
obedient dusk

Latest Threads

Top