I am using SoapRequst For my Desktop application. but There is one Soap request in which i hav to Send xml Document but when i tried to add that xml file means Document then that is converted into the String format i means all "<>" clauses converted into the String formate "<" like this.
So what i should do to make them remain into the XMl format.
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<Update xmlns="http://tempuri.org/">
<doc>xml</doc>
</Update>
</soap:Body>
</soap:Envelope>
when i am sending file its converted to this.
**><Folder><**
that has to be this
<Folder>
Can i have your valuble suggestion for this thanks in advance.
here my method is. public static SOAPMessage UpdateAllGroupWithSwitchUserConfiguration() {
try {
File f = new File("/com/package/package/TreeModel.xml");
BufferedReader br = new BufferedReader(new FileReader(f));
StringBuffer builder = new StringBuffer();
String xml = "";
while ((xml = br.readLine()) != null) {
builder.append(xml.trim());
}
MessageFactory messageFactory = MessageFactory.newInstance();
SOAPMessage soapMessage = messageFactory.createMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();
String serverURI = "http://tempuri.org/";
// SOAP Envelope
SOAPEnvelope envelope = soapPart.getEnvelope();
envelope.addNamespaceDeclaration("tem", serverURI);
SOAPElement sOAPElement = envelope.addChildElement("UpdateAllGroupWithSwitchUserConfiguration", "tem");
String XML_String = builder.toString();
// DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
// DocumentBuilder doc_builder = factory.newDocumentBuilder();
//
// Document document = doc_builder.parse(new InputSource(new StringReader(XML_String)));
//
// TransformerFactory factory1 = TransformerFactory.newInstance();
// Transformer transformer = factory1.newTransformer();
// Source source = new DOMSource(document);
// Result result = new StreamResult(xml);
// transformer.transform(source, result);
SOAPElement xml_APElement = sOAPElement.addChildElement("doc", "tem");
xml_APElement.addTextNode(builder.toString());
MimeHeaders headers = soapMessage.getMimeHeaders();
headers.addHeader("SOAPAction", serverURI + "UpdateAllGroupWithSwitchUserConfiguration");
soapMessage.saveChanges();
/*
* Print the request message
*/
System.out.print("Request SOAP Message = ");
soapMessage.writeTo(System.out);
return soapMessage;
} catch (Exception e) {
}
return null;
}
i have put on comment what i have tried.