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;
...
}