aspose file tools*
The moose likes XML and Related Technologies and the fly likes How to create XML from XSD dynamically at runtime Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "How to create XML from XSD dynamically at runtime" Watch "How to create XML from XSD dynamically at runtime" New topic
Author

How to create XML from XSD dynamically at runtime

harbeer kadian
Greenhorn

Joined: Jul 07, 2009
Posts: 12
Hi,

I have got a requirement, where a client has to send a XML inside another xml tag to a web service.
For ex:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tut="http://tutorial.com">
<soapenv:Header/>
<soapenv:Body>
<tut:sayHello>
<tut:name>
<![CDATA[
<Details>
<FirstName>Harbeer</FirstName>
<LastName>Kadian</LastName>
<Details>
]]>
</tut:name>
</tut:sayHello>
</soapenv:Body>
</soapenv:Envelope>

The information inside CDATA will be used to create another soap message. The server will create the another soap message and will use it to invoke another
web service which may exist on some other server.

The problem here is that the xsd for xml given in CDATA is not known to the client.
Now I need my server to pass this information to the client. The server has the required xsd for the xml inside CDATA.
The communication between client and server is through java web service.

Please tell how we can pass this information to the client.

With Regards
Harbeer kadian
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12806
    
    5
The problem here is that the xsd for xml given in CDATA is not known to the client.


What does the client know?

How is the client generating the initial request?

Based on my experience, sending XML inside CDATA is a very bad design and has the potential for causing all sorts of problems. Perhaps it is time to rethink the design.

Bill
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18658
    
    8

What's the relationship between "a web service" and "my server"? And is the "client" a client of your server and of the web service, or only a client of one of them?
harbeer kadian
Greenhorn

Joined: Jul 07, 2009
Posts: 12
This will be some thing like this:

The client will invoke an operation on the server web service (Some thing like getInuputMessageStructureForOperation()).
The client will pass the name of wsdl with which he wants to communicate.
The server web service here is acting as a transportation layer, which intercepts client soap messages, and after reading the
information inside soap message, create another soap message and parses the appropriate wsdl file to know what is the valid
input xml structure required to invoke an operation.
In my case Apache ServiceMix Enterprise Service Bus is acting as the server web service.
The other web service may exist on a tom cat server.

The ServiceMix has the wsdl to talk to the webservice existing on the tom cat server.
Now I am thinking some thing like this, tell me if it has flaws
The serviceMix will parse the wsdl, when the client will invoke the method getInuputMessageStructureForOperation() in which client
will pass the name of operation and the name of wsdl.

Now I have to parse the wsdl and have to send the input message structure(which is defined as xsd) back to the client.
For ex:

<schema elementFormDefault="qualified" targetNamespace="http://tutorial.com" xmlns="http://www.w3.org/2001/XMLSchema">
<element name="sayHello">
<complexType>
<sequence>
<element name="name" type="xsd:string"/>
</sequence>
</complexType>
</element>
</schema>
<wsdl:message name="sayHelloRequest">
<wsdl:part element="impl:sayHello" name="parameters"/>
</wsdl:message
<wsdlperation name="sayHello">
<wsdl:input message="impl:sayHelloRequest" name="sayHelloRequest"/>
<wsdlutput message="impl:sayHelloResponse" name="sayHelloResponse"/>
</wsdlperation>

So that next time when he want to invoke that operation, he can use the xsd input message structure to create valid xml.

As the server web service is independent of the webservice residing on tom cat.
Hence I thought that I will pass the soap message required for tom cat inside a xml tag defined for server web service.
Some thing like content tag.
So that at server web service, i will invoke getContent() method which will give me an xml.
Change the xml to a soap message and communicate it to the web service on tom cat.

As i have never done this type of programming, hence I have no clue regarding how to send the xsd structure back to the client.
Please help.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to create XML from XSD dynamically at runtime