Em Terça 29 Novembro 2005 17:50, o Gabsaga Tata escreveu:
> I have an XML string that I want to send to my web service so that the
> service can process it.
>
> String xmlString =
> "<Message><From>Me</From><To>You</To><Text>Hello</Text></Message>";
>
> How can a client send this to a web service and the service convert this
> into a DOM Object for processing?
>
> I tried the following but it didn't work. Any help will be appreciated.
>
> Client code looks like the following:
>
>  com.ws.MyService service = new com.ws.MyServiceLocator();
>  // Now use the service to get a stub to the service
>  com.ws.Serve sv = service.getcipher();
>  sv.processRequest(xmlString);
>
> Service code looks like the following:
>
>  DocumentBuilderFactory docBuilderFactory =
> DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder =
> docBuilderFactory.newDocumentBuilder(); Document doc = docBuilder.parse(new
> InputSource(new StringReader(xmlString)));
>

You just want to convert an xml String to document ? Not really a web services 
question, but anyways...

    /** Convert String to a W3C XML Document.
    @param xmlString String to convert
    @return Document W3C XML Document
    @throws XMLHelperException all errors
    */
    public static final Document getDocument(String xmlString)
        throws XMLHelperException {
        try {
     
            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);
        } catch (Exception ex) {
            throw new XMLHelperException("String to XML Document Error for "
                  + "String:\n\n " + xmlString + " ", ex);
        }
    }

HTH,
iksrazal

Reply via email to