users@saaj.java.net

RE: [SAAJ-USR] RE: [Fwd: Using "removeNamespaceDeclaration()" is sometimes ignored]

From: Karr, David <David.Karr_at_wamu.net>
Date: Tue, 16 Dec 2003 13:44:26 -0800

Ok. I was thinking the "Name" creator method didn't help me, but
thinking about this again, I see that it does. The revised code now
works, without having to call "removeNamespaceDeclaration()".

        -----Original Message-----
        From: Phil Goodwin [mailto:Phil.Goodwin_at_Sun.COM]
        Sent: Tuesday, December 16, 2003 1:11 PM
        To: users_at_saaj.dev.java.net
        Subject: Re: [SAAJ-USR] RE: [Fwd: Using
"removeNamespaceDeclaration()" is sometimes ignored]
        
        
        Karr, David wrote:
        

                I've been having an email conversation with some of the
SAAJ developers, but they asked me to take this question to the list, so
here it is.
                 
                I was noticing that the output of my code using SAAJ was
that namespace declarations added to parent nodes would result in the
child nodes also having the namespace declaration. Although technically
ok, I wanted to "clean up" the resulting output, to remove the redundant
namespace declarations in the child nodes.
                 
                I was able to get this to work by manually using
"removeNamespaceDeclaration" on the resulting child nodes, but that
seems odd to me. After I asked about this, I was told that if I "use
the parent element to create the child", instead of using the factory,
then it will not add the namespace declaration. Now I would ask, how do
I use the parent element to create the child? I thought the SOAPFactory
was the only way to create SOAPElements.

        From SOAPElement.java:
        
        public interface SOAPElement extends Node, org.w3c.dom.Element {
        
            /**
             * Creates a new <code>SOAPElement</code> object initialized
with the
             * given <code>Name</code> object and adds the new element
to this
             * <code>SOAPElement</code> object.
             *
             * @param name a <code>Name</code> object with the XML name
for the
             * new element
             *
             * @return the new <code>SOAPElement</code> object that was
created
             * @exception SOAPException if there is an error in creating
the
             * <code>SOAPElement</code> object
             */
            public SOAPElement addChildElement(Name name) throws
SOAPException;
        
            /**
             * Creates a new <code>SOAPElement</code> object initialized
with the
             * specified local name and adds the new element to this
             * <code>SOAPElement</code> object.
             *
             * @param localName a <code>String</code> giving the local
name for
             * the element
             * @return the new <code>SOAPElement</code> object that was
created
             * @exception SOAPException if there is an error in creating
the
             * <code>SOAPElement</code> object
             */
            public SOAPElement addChildElement(String localName) throws
SOAPException;
        
            /**
             * Creates a new <code>SOAPElement</code> object initialized
with the
             * specified local name and prefix and adds the new element
to this
             * <code>SOAPElement</code> object.
             *
             * @param localName a <code>String</code> giving the local
name for
             * the new element
             * @param prefix a <code>String</code> giving the namespace
prefix for
             * the new element
             *
             * @return the new <code>SOAPElement</code> object that was
created
             * @exception SOAPException if there is an error in creating
the
             * <code>SOAPElement</code> object
             */
            public SOAPElement addChildElement(String localName, String
prefix)
                throws SOAPException;
        
            /**
             * Creates a new <code>SOAPElement</code> object initialized
with the
             * specified local name, prefix, and URI and adds the new
element to this
             * <code>SOAPElement</code> object.
             *
             * @param localName a <code>String</code> giving the local
name for
             * the new element
             * @param prefix a <code>String</code> giving the namespace
prefix for
             * the new element
             * @param uri a <code>String</code> giving the URI of the
namespace
             * to which the new element belongs
             *
             * @return the new <code>SOAPElement</code> object that was
created
             * @exception SOAPException if there is an error in creating
the
             * <code>SOAPElement</code> object
             */
            public SOAPElement addChildElement(String localName, String
prefix,
                                               String uri)
                throws SOAPException;
        ...
        }