0

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.

**&gt;&lt;Folder&gt;&lt;**

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.

Kishan Bheemajiyani
  • 3,429
  • 5
  • 34
  • 68

1 Answers1

0

Well, it depends on how the structure of you main XML document is defined. Can you post the XSD? E.g. if in the main XSD you define the doc element to be from another specific XSD with a given namespace eg. "myExternalDocumentNamespace", then you can include it the way you tried, just adding the namespace of the element, e.g.

<Folder xmlns="myExternalDocumentNamespace">
...
</Folder>

Depending on your case you may prefer to use an xs:any element in the main XSD, though in the end that also boils down to the same.

Rudi Angela
  • 1,463
  • 1
  • 12
  • 20