Here's an example of what I mean:

package cafe;

import static java.lang.System.out;
import java.io.StringReader;
import java.io.StringWriter;

import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.dom.DOMSource;

import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;


/** Um exemplo como a cliente pode pegar um nó . */
public class GetSoapNode {

    /** Run the client.
     * @param args for main() */
    public static void main(String[] args) {
        try {
            doGetNode();
            out.println("doGetNode completed!!!");

        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    /** Executa a chamada. */   
    private static void doGetNode() {
   
        String xml = "<?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"><soapenv:Header /><soapenv:Body><simpleLoginResponse xmlns=\"http://simpleNS/types\"><soap_session_id>my random string</soap_session_id><web_user_name xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:nil=\"true\" /></simpleLoginResponse></soapenv:Body></soapenv:Envelope>";

        try {
            Document doc = getDocument(xml);
            NodeList nodeList = doc.getElementsByTagName("soap_session_id");

            // What you do next depends a lot on what is in myNode -
            // you may have attributes, child elements, etc.           
            Node myNode = nodeList.item(0);
            out.println(getNodeToString(myNode));
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    /** Converter node para string
    @param   nodeName  node a converter
    @return  String    String convertida
    @throws  XMLHelperException
    */
    private static final String getNodeToString(Node node) throws Exception {
        TransformerFactory tFactory = TransformerFactory.newInstance();
        Transformer transformer = tFactory.newTransformer();
        transformer.setOutputProperty("omit-xml-declaration", "yes");
 
        StringWriter sw = new StringWriter();
        StreamResult result = new StreamResult(sw);
        DOMSource source = new DOMSource( node );
        transformer.transform( source, result );
 
        return sw.getBuffer().toString();
    }

    /** Convert String to a W3C XML Document.
    @param xmlString String to convert
    @return Document W3C XML Document
    @throws XMLHelperException all errors
    */
    private static final Document getDocument(String xmlString)
        throws Exception {

        DocumentBuilderFactory factory =
            DocumentBuilderFactory.newInstance();
        factory.setNamespaceAware(true);
        factory.setIgnoringElementContentWhitespace(false);
        DocumentBuilder builder = factory.newDocumentBuilder();

        InputSource isXml = new InputSource(new StringReader(xmlString));
        return builder.parse(isXml);
    }       
}

You can change the argument in doc.getElementsByTagName("soap_session_id") - to any other node to get an idea of what the code is doing.

BTW, since you are studying I recommend using Axis2 - its the future ;-) . Here's a tutorial in português:

http://www.braziloutsource.com/wss2.html

HTH,
Robert
http://www.braziloutsource.com/


On 5/22/06, Gabriel Moura <[EMAIL PROTECTED]> wrote:

well,

I am beginning and I did not understand very well.
you can detail as you show the result? for example,
System.out.println(????????).

I want to show in my java aplication for example, only:
<helloReturn xsi:type="xsd:string">HELLO TESTING....</helloReturn>

thanks!
--
View this message in context: http://www.nabble.com/show+a+method+return+in+xml+response-t1664824.html#a4513290
Sent from the Axis - User forum at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Reply via email to