Apache Axis XMLUtils.ElementToString()

A

au714

I'm having trouble understang the XMLUtils.ElementToString() method. I
am unable to satisfactorily output the contents of a SOAPBody when that
SOAPBody contains a SOAPFault. However I am able to output the conents
of the entire SOAPMessage with a different API.

Based on that, I think the SOAPMessage is good. What don't I
understand about the use of XMLUtils.ElementToString()?




Here is the (good) output using message.writeTo(System.out)
--------------------------------------------
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.or
g/2001/XMLSchema-instance">
<soapenv:Body>
<soapenv:Fault>
<faultcode
xmlns:ns1="http://xml.apache.org/axis/">ns1:Server.generalException</faultcode>
<faultstring>What in the world!!!</faultstring>
<faultactor>http://localhost:8080/myServices</faultactor>
<detail/>
</soapenv:Fault>
</soapenv:Body>
</soapenv:Envelope>

Here is the output using XMLUtils.PrettyElementToStream(envelope,
System.out)
-------------------------------------------------------
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header/>
<Body>
<Fault/>
</Body>
</soapenv:Envelope>




And here is the code:

import javax.xml.soap.*;
import org.apache.axis.utils.*;

public class Test {
public static void main(String[] args) {
try {
SOAPMessage message =
MessageFactory.newInstance().createMessage();
SOAPEnvelope envelope = message.getSOAPPart().getEnvelope();
SOAPBody body = message.getSOAPBody();
SOAPFault fault = body.addFault();
fault.setFaultString("What in the world!!!");
fault.setFaultActor("http://localhost:8080/myServices");

message.writeTo(System.out);
System.out.println();
System.out.println("-----------------------------------------");
XMLUtils.PrettyElementToStream(envelope, System.out);
System.out.println();
if (fault instanceof org.w3c.dom.Element) {
System.out.println("fault instanceof org.w3c.dom.Element");
}
}
catch (Exception ex) {
ex.printStackTrace();
}
}
}



I'm using Axis 1.2.1.

java -version
java version "1.4.2"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2-b28)
Java HotSpot(TM) Client VM (build 1.4.2-b28, mixed mode)



Thanks in advance,
FGB
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,795
Messages
2,569,644
Members
45,357
Latest member
RuthEsteve

Latest Threads

Top