Home arrow XML arrow Send Part of an XForms Instance to a Web Service
XML

Send Part of an XForms Instance to a Web Service


Include your SOAP request within a general instance document: This intermediate level article by Nicholas Chase explains how an XForms form is handy as a Web service client because it enables you to easily send and receive an XML document, but what if you don't necessarily want to send the entire data instance? This tip explains how you can build an instance that includes a SOAP message along with other data, and then send only the SOAP message on submission. (This article originally appeared on IBM developerWorks, 13 Aug 2004, at http://www.ibm.com/developerWorks.)

Author Info:
By: developerWorks
Rating: 4 stars4 stars4 stars4 stars4 stars / 9
November 02, 2004
TABLE OF CONTENTS:
  1. · Send Part of an XForms Instance to a Web Service
  2. · Structuring the form
  3. · Creating the submission
  4. · Resources

print this article
SEARCH DEVARTICLES

Send Part of an XForms Instance to a Web Service
(Page 1 of 4 )

In previous tips, you've discovered how an XForms form can easily send a Web service request and receive the response, but in all of those cases you were sending the entire instance to the Web service. However, this may not always fit with your plans. For example, the SOAP message may be part of a larger instance document that includes related data. In this tip, you'll learn how to create an XForms form around an instance that includes more than just a SOAP message and then send only the SOAP message on submission. This tip assumes that you are generally familiar with XForms and that you have the FormsPlayer XForms client installed. (See Resources for more information.)

The instance

Start by creating the basic form, including the instance, as shown in Listing 1:

Listing 1. The basic form


<html
  xmlns="http://www.w3.org/1999/xhtml"
  xmlns:xforms="http://www.w3.org/2002/xforms"
  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
  xmlns:ev="http://www.w3.org/2001/xml-events"
  xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
>
  <head>
    <title>XForms and Web Services</title>
  </head>
  <body>
   <object id="FormsPlayer"
        classid="CLSID:4D0ABA11-C5F0-4478-991A-375C4B648F58">
     <b>FormsPlayer has not loaded. Please check your installation.</b>
   </object>
   <?import namespace="xforms" implementation="#FormsPlayer" ?>

   <xforms:model id="WeatherService">

      <xforms:instance id="weatherInstance" >

        <data>
          <employees>
            <emp id="1">
              <name>Nick</name>
                <zip>10314</zip>
            </emp>
            <emp id="2">
                <name>Troy</name>
                <zip>90210</zip>
            </emp>
            <emp id="3">
              <name>Bob</name>
              <zip>34652</zip>
            </emp>
          </employees>
          <soapmessage>
          <SOAP-ENV:Envelope
             xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
             xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
             xmlns:xsd="http://www.w3.org/1999/XMLSchema">
            <SOAP-ENV:Body>
              <ns1:getTemp xmlns:ns1="urn:xmethods-Temperature"
                 SOAP-ENV:encodingStyle=
                      "http://schemas.xmlsoap.org/soap/encoding/">
                 <zipcode xsi:type="xsd:string"></zipcode>
              </ns1:getTemp>
            </SOAP-ENV:Body>
          </SOAP-ENV:Envelope>
        </soapmessage>
       </data>

      </xforms:instance>

    </xforms:model>

</body>
</html>

The instance has two basic parts: the employees data and the SOAP message, contained in the soapmessage element. You'll use the employees data to populate the SOAP message before submitting it. To do that, add a select1 control that presents each of the employees as an option, as shown in Listing 2:

Listing 2. Adding a select1 menu

...
      </xforms:model>

      <xforms:select1 appearance="minimal"
                     ref="instance('weatherInstance')//zipcode">
         <xforms:label>Choose Employee</xforms:label>
         <xforms:itemset nodeset="instance('weatherInstance')//emp">
           <xforms:label ref="name"/>
           <xforms:value ref="zip"/>
         </xforms:itemset>
      </xforms:select1>

</body>
</html>

This control loops through each of the available emp elements and creates a drop-down menu, as shown in Figure 1.

Figure 1: The basic data control
Send part of an XForms instance to a Web service

Because you've set the select1 element's ref attribute to point to the SOAP message's zipcode element, simply changing the drop-down menu adds the appropriate value to the Web service request.

Before you get to the submission, fill in the rest of the form.

IBM developerWorksVisit developerWorks for thousands of developer articles, tutorials, and resources related to open standard technologies, IBM products, and more. See developerWorks.


blog comments powered by Disqus
XML ARTICLES

- Open XML Finally Supported by MS Office
- XML Features Added to Two Systems
- Using Regions with XSL Formatting Objects
- Using XSL Formatting Objects
- More Schematron Features
- Schematron Patterns and Validation
- Using Schematron
- Datatypes and More in RELAX NG
- Providing Options in RELAX NG
- An Introduction to RELAX NG
- Path, Predicates, and XQuery
- Using Predicates with XQuery
- Navigating Input Documents Using Paths
- XML Basics
- Introduction to XPath

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials