This is partly my fault in using the term detach (I've had too much SAAJ
recently). You need to think in terms of DOM programming. What you have
are two DOM nodes, each if these Nodes should be a DOM Element. So you
can do this
Node nodeIJustCreated = getThisNodeFromDocIJustCreated();
Node nodeInSOAPMessage = getSOAPMessage();
// now import it into the SOAPMessage
Document docSOAPMessage = nodeInSOAPMessage.getOwnerDocument();
Node import = docSOAPMessage.importNode(nodeIJustCreated);
// node is owned by the document by is not 'attached' yet
nodeInSOAPMessage.appendChild(import);
Hope this makes sense!
Kevin Jones
http://kevinj.develop.com
> -----Original Message-----
> From: Karr, David [mailto:David.Karr_at_wamu.net]
> Sent: 06 December 2003 00:05
> To: users_at_jax-rpc.dev.java.net
> Subject: RE: Adding SOAPHeader children from a NodeList
>
>
> Ok, but how do you do that? I see what might be disconnected
> pieces that are needed for this, but I can't find an end to
> end solution for this. I see the
> "javax.xml.soap.Node.detachNode()" method, which might be
> what you're getting at, but I don't see how to make an object
> of that class from my "org.w3c.com.Element" object. I also
> see the "org.w3c.dom.Document.importNode(org.w3c.dom.Node)"
> method, but I don't see what I can do with that.
>
> > -----Original Message-----
> > From: Kevin Jones [mailto:kevinj_at_develop.com]
> >
> > A node cannot be part of two DOMs, you'll need to detach it
> > from one and
> > import it into the SOAPMessage DOM,
> >
> > Kevin Jones
> > http://kevinj.develop.com
> >
> > > -----Original Message-----
> > > From: Karr, David [mailto:David.Karr_at_wamu.net]
> > >
> > > I need a real SOAPMessage. My downstream API is
> depending on that.
> > >
> > > So let's say I've parsed a document into a Document. I've
> > > created an empty SOAPMessage. I've found an Element that I
> > > want to just copy into my SOAPMessage header, along with
> > > other elements, either copied or created manually.
> > >
> > > I tried just using the "Node.appendChild(Node)" method, as
> > > SOAPElement is just a Node, as you say. Unfortunately, this
> > > failed with:
> > >
> > > ---------------
> > > WRONG_DOCUMENT_ERR: A node is used in a different document
> > > than the one that created it.
> > > org.w3c.dom.DOMException: WRONG_DOCUMENT_ERR: A node is used
> > > in a different document than the one that created it.
> > > at org.apache.xerces.dom.ParentNode.internalInsertBefore(Unknown
> > > Source)
> > > at org.apache.xerces.dom.ParentNode.insertBefore(Unknown Source)
> > > at org.apache.xerces.dom.NodeImpl.appendChild(Unknown Source)
> > > ---------------
> > >
> > > I tried passing the node to be copied through
> > > "cloneNode(true)", but that had no effect.
> > >
> > > > -----Original Message-----
> > > > From: Kevin Jones [mailto:kevinj_at_develop.com]
> > > >
> > > > Do you actually need a SOAPMessage or do you need a
> SOAP message?
> > > >
> > > > I find that using SAAJ to build anything apart from a
> > SOAP fault a
> > > > complete pain. You're almost certainly better off in this
> > > case using
> > > > DOM/JDOM/StAX/JAXB rather than SAAJ.
> > > >
> > > > Even if you need a SOAPMessage you can build the data using
> > > one of the
> > > > other APIs and then import it (call addDocument on the
> > > SOAPBody), and
> > > > remember that in the latest version of SAAJ everything is an
> > > > org.w3c.dom.Node, so at the very least you can treat it
> > like a DOM.
> > > >
> > > > BTW, SAAJ like many Java APIs is factory based to allow for
> > > multiple
> > > > implementations which makes the API harder to use and in
> > > the case of
> > > > SAAJ, which is a relatively simple API, is something of
> > an overkill
> > > > (IMHO of course),
> > > >
> > > > Kevin Jones
> > > > http://kevinj.develop.com
> > > >
> > > > > -----Original Message-----
> > > > > From: Karr, David [mailto:David.Karr_at_wamu.net]
> > > > > Sent: 04 December 2003 21:49
> > > > > To: users_at_jax-rpc.dev.java.net
> > > > > Subject: Adding SOAPHeader children from a NodeList
> > > > >
> > > > >
> > > > > I'm trying to construct a SOAPMessage from a message that is
> > > > > "soap-like". It has a "header" element and a "body" element,
> > > > > but it doesn't quite match the SOAP 1.1 schema, so I can't
> > > > > create a SOAPMessage directly from it.
> > > > >
> > > > > So, I need to create an empty SOAPMessage and then
> add pieces to
> > > > > it. I'm trying to figure out the easiest way to get
> some of this
> > > > > done. It appears that I have to take the SOAPHeader object
> > > > > obtained from the SOAPMessage and use the
> > > > > "addChildElement(SOAPElement)" method from the
> SOAPElement base
> > > > > class. It appears that I can't create SOAPElement objects
> > > > > directly, I have to use the "SOAPFactory.createElement()"
> > > > > method. This has overloaded versions of "(name)",
> > > > > "(localName)", and "(localName,
> > > prefix, uri)".
> > > > >
> > > > > It appears that I have to create a SOAPElement using a
> > > > > particular name (copied from the original), and then manually
> > > > > add the content of that element.
> > > > >
> > > > > Isn't there an easier way to do this?
> > > > >
> > > > >
> > > >
> > >
> >
> ---------------------------------------------------------------------
> > > > > To unsubscribe, e-mail: users-unsubscribe_at_jax-rpc.dev.java.net
> > > > > For additional commands, e-mail:
> users-help_at_jax-rpc.dev.java.net
> > > > >
> > > > >
> > > >
> > > >
> > > >
> > >
> >
> ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail: users-unsubscribe_at_jax-rpc.dev.java.net
> > > > For additional commands, e-mail: users-help_at_jax-rpc.dev.java.net
> > > >
> > > >
> > >
> > >
> >
> ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: users-unsubscribe_at_jax-rpc.dev.java.net
> > > For additional commands, e-mail: users-help_at_jax-rpc.dev.java.net
> > >
> > >
> >
> >
> >
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe_at_jax-rpc.dev.java.net
> > For additional commands, e-mail: users-help_at_jax-rpc.dev.java.net
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jax-rpc.dev.java.net
> For additional commands, e-mail: users-help_at_jax-rpc.dev.java.net
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe_at_jax-rpc.dev.java.net
For additional commands, e-mail: users-help_at_jax-rpc.dev.java.net