keskiviikko 10. huhtikuuta 2013

Tutorial 1 part 11 - create XML schema with jDeveloper

Create XML schema with jDeveloper

Now we can start creating our service. First thing is to define what the service interface looks like. With web services the service definition consists of two parts: messages are received and returned as XML messages and the format for messages is defined in XML schema as xsd files. The WSDL files on the other hand define what is the name of our service, what operations it has, what messages each operation receive and return and they can also can contain binding information telling what protocol (like SOAP) the service is using and what is the address of the service (port it is listening to etc.).

You start by selecting

New->All Technologies->General->XML- Schema->Ok

Add name and target namespace

Note: It would be better to generate the xml schema in subdirectory xsd rather than at the main level of  the project. JDeveloper creates files into the directory where the focus is on the Application Navigator window (most rightmost window by default where you see your project). Just click once over the xsd folder and then create the xml schema file and it will be created in the right directory. You can also later drag and drop files to new directories. Sometimes however jDeveloper may not do the refactoring correctly and you may need to edit some file manually (at least in older patchsets there were issues like this from time to time).
Now you are ready to start editing XML schema.
Change the name of the XML element to e.g. vehicleStatusQuery. You do this with the right mouse click over the exampleElement and following the dialog as follows to refactoring:



Next we’ll add elements to the query. Right click on top of the vehicleStatusQueryElement and select “insert inside element” and select a sequence.
Add new element to the sequence by for example right clicking on top of sequence and selecting “Insert inside sequence”


Add three elements. You can rename them by clicking on top of each one and directly editing to change the name. Name them  as license_number, event_time and vehicle_type. They have no types yet, only names



Double-click on first one and select “Set Type”




Select xsd:string from the shown combo-box.
Set the types for other elements as follows: event_time (xsd:datetime) and vehicle_type (xsd:string)
Note: There are several ways to set the types and edit the XML schema in general.
As an alternative way you can change the type of the attribute also by directly editing it in the Property Inspector. By default this form is on the bottom part of on the right side but you can organize the windows as you see best fit or even close them. If you edit it in the form, you would directly add the string xs:string to the input field there.
A third way to edit the xml schema is to switch to the source view. There is a tab at the bottom of the visual XML schema editor with the test “source”. By clicking it you can directly see the generated XML schema file and edit it directly. When you switch back to the graphical view the changes are reflected.
Still one more way is to use drag-and-drop from Component Palette directly to the XSD canvas. You can experiment how this works with jDeveloper. In practice this is probably the fastest way but I’ve often used context menus



First element is ready.
Next we add an element for the return value. Let’s call it vehicleStatusResponse. 
1.       Double-click on top of the schema and select Insert inside Schema->Element.
2.       Rename it to vehicleStatusResponse (by clicking on it and directly editing)
3.       Add a sequence (e.g. by right-click->insert inside element->sequence)
4.       Add one element to the sequence (right click on top of the sequence->insert inside sequence->element
5.       Rename the newly added element as “status” (click on it and edit directly)



We are almost there. You may also take a peek at the generated XML schema. Select the source tab and the generated XML schema file is shown. You can also directly edit the schema file and changes will be reflected on the graphical side.


Let’s still add a code for faults. Call this new element as vehicleStatusFault and add it one element called faultCode and make it an xsd:integer.


In principle that is all we need. For future we could add a couple of additional attributes: event_time (xsd:datetime) and vehicle_type (xsd:string). Event_time would be the time when the event happened, this would allow us to make checks even when the request is delayed for some reason (e.g. it could be that now the car is not rented out but if the event is from previous day, it could have been rented, we’ll skip finesses like this here).


That’s it – we have created a XML schema.



Now we have done first iteration of our schema. It’s time to make the service.
 




2 kommenttia:

  1. hi how can we create an xml doc from xsd in jdevloper

    VastaaPoista

  2. Hi, how can we create very very complex xsd in SOA like using import schemas, include schemas.































































































































































































































    VastaaPoista