try to treat the SOAP enveloppe response in my java class

hi all

i have a simple class that call a webservice and gets back an xml response, with SOAP.

here is a sample :

HTTP/1.1 200 OK

Content-Type: text/xml; charset=utf-8

Content-Length: length

<?xml version="1.0" encoding="utf-8"?>

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">

<soap:Body>

<BonjourResponse xmlns="http://tempuri.org/">

<BonjourResult>Bonjour string</BonjourResult>

</BonjourResponse>

</soap:Body>

</soap:Envelope>

i just want to get the string sent in the response (between the <BonjourResult> tags)

what should i do to treat this xml ?

for the moment i retrieve this xml this way :

URL endpoint = new URL("http://val1nt10/PCS_Integration/SynchronizeProfiles.asmx");

URLConnection con = endpoint.openConnection ();

con.setDoInput (true);

con.setDoOutput (true);

con.setUseCaches (false);

con.setAllowUserInteraction(false);

con.setRequestProperty ("Content-Length", Integer.toString (request.length));

con.setRequestProperty ("Content-Type", "text/xml; charset=utf-8");

con.setRequestProperty ("SOAPAction", "\"http://tempuri.org/Bonjour\"");

OutputStream out = con.getOutputStream ();

out.write (request);

out.flush ();

out.close();

InputStream in = con.getInputStream();

regards,

[1595 byte] By [DelisE] at [2007-9-26 21:10:44]
# 1

that's okay i found a solution to my problem :

InputStream in = con.getInputStream();

com.ibm.xml.parsers.DOMParser parser = new com.ibm.xml.parsers.DOMParser();

parser.parse(new InputSource(in));

Document doc = new DocumentImpl();

Envelope env = new Envelope();

Body body = new Body();

doc = parser.getDocument();

NodeList nl = doc.getElementsByTagName("mytag");

NodeList nl2 = ((Element) nl.item(0)).getChildNodes();

for (int i = 0; i < nl2.getLength(); i++)

{

Result += DOM2Writer.nodeToString(nl2.item(i)).trim();

}

out.close();

}

DelisE at 2007-7-3 20:35:04 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 2
it would be much easier to use the JAXM-API. Then you could do something like this:string = msg.getSoapPart().getEnvelope.getBody().getFirstChild() ... getText()(syntax can be different)
voegler at 2007-7-3 20:35:04 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 3
for this instantiation --> com.ibm.xml.parsers.DOMParser parser = new com.ibm.xml.parsers.DOMParser();do i need to import some calss or statement
student82 at 2007-7-3 20:35:05 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 4
regarding string = msg.getSoapPart().getEnvelope.getBody().getFirstChild() ... getText()how do i go abt it?is it like this --> SOAPEnvelope envelope = sm.getSOAPPart().getEnvelope();SOAPBody body = envelope.getBody();How to get this "msg"?
student82 at 2007-7-3 20:35:05 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 5

Codes:

DOMParser parser = new DOMParser();

InputSource is = new InputSource(in);

parser.parse(is);

Document doc = new DocumentImpl();

doc = parser.getDocument();

System.out.println("document: " + doc);

Envelope env = new Envelope();

System.out.println("env: " + env);

System.out.println("envgetbody: " + env.getBody());

Body body = new Body();

System.out.println("body: " + body);

Results:

document: [#document: null]

env: [Attributes={ xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xm

lns:xsi="http://www.w3.org/1999/XMLSchema-instance" xmlns:xsd="http://www.w3.org

/1999/XMLSchema"}] [Header=null] [Body=null] [EnvelopeEntries=]

envgetbody: null

body: [Attributes={}] [BodyEntries=]

Y the document is null since i had assigned it?

student82 at 2007-7-3 20:35:05 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...