Declaring Variables with <xm:bind>

You can use the <xm:bind> attribute to declare a new variable for use in an XML map. Note that the variable you declare with <xm:bind> is available only within the scope of the element in which you declare it, and children of that element.

The following example declares a new Address variable a and binds it to the address within the method's customerData parameter. Because it is declared in the <address> element, the new variable is available to the <street> and <zip> elements, which are its children.

    /**
     * @jws:operation
     * @jws:return-xml xml-map::
     *     <customer>
     *         <name>{String customerData.name}</name>
     *         <address xm:bind="Address a is customerData.address">
     *             <street>{a.street}</street>
     *             <zip>{a.zip}</zip>
     *         </address>
     *     </customer>
     *     ::
     */
    public void addCustomerData(MyStructure customerData)
    {
        System.out.println("Customer name is " + customerData.get("name"));
        System.out.println("Customer zipcode is " +
            ((Address)customerData.get("address")).zip);
    }

For reference information on <xm:bind>, see <xm:bind> Attribute.

Related Topics

Matching XML Shapes

Binding to Java Data Structure Members

<xm:bind> Attribute