You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@xmlbeans.apache.org by Roland Schemers <sc...@stanford.edu> on 2003/10/07 23:38:00 UTC

cursor question...

Hi. I've got a quick question object whether or not using cursors is the
right (and/or only) approach to what I'm trying to do.

I've got an XmlObject which represents the body of a SOAP message
to construct, and I want to wrap an envelope around it. 

Compiling the SOAP 1.2 xsd (with a prefix of Soap12), gives me an
xmlbean class called:

Soap12Body

That declares no methods of its own, just inherits from XmlObject and
XmlTokenSource. I'm guessing in order to add the XmlObject to
that Body, I have to use a cursor. 

I ended up writing this:

    /** Given an XmlObject, wrap it in an envelope and return it */
    public XmlObject soapEnvelope(XmlObject document)
    {
        Soap12EnvelopeDocument soapEnv = 
            Soap12EnvelopeDocument.Factory.newInstance();
        Soap12Body soapBody = soapEnv.addNewEnvelope().addNewBody();

        XmlCursor sc = null, dc = null;
        try {
            sc = soapBody.newCursor();
            sc.toNextToken();
            dc = document.newCursor();
            dc.toNextToken();
            dc.copyXml(sc);
        } finally {
            if (sc != null)
                sc.dispose();
            if (dc != null)
                dc.dispose();
        }
        return soapEnv;
    }

Is there a better approach to doing this, or is this indeed the
correct use of cursors? It seems to work fine, just wasn't sure if it
was the most efficient way.

thanks, roland

- ---------------------------------------------------------------------
To unsubscribe, e-mail:   xmlbeans-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xmlbeans-user-help@xml.apache.org
Apache XMLBeans Project -- URL: http://xml.apache.org/xmlbeans/