<xm:multiple> Attribute

Specifies the data structure variable to which a specific repeating XML element should be mapped.

# Syntax

    <elementName
        xm:multiple="[dataType ]arrayMemberVariable in [dataType ]arrayVariable[, …]"
    >

# Attributes

xm:multiple

A statement expressing the mapping between an element's value and a method variable, and the variable's role as a member of an array.

# Remarks

Use the <xm:multiple> tag to capture the values of repeating XML elements. In the following XML example, the <part> element (and its children) repeats three times. Because this repetition resembles a list, you can capture the repeating values by mapping them to a data structure.

    <order>
        <part>
            <partID>19573</partID>
            <partQuantity>1</partQuantity>
        </part>
        <part>
            <partID>28912</partID>
            <partQuantity>1</partQuantity>
        </part>
        <part>
            <partID>39485</partID>
            <partQuantity>57</partQuantity>
        </part>
    </order>

The <xm:multiple> attribute assumes that your Java code has declared collections to store the values of each repeating element. The syntax of the <xm:multiple> attribute's value essentially assigns each value of the repeating element to a place in the collection, which your code can then inspect iteratively.

Note The in operator is a reserved word in the context of the <xm:multiple> attribute. This means that using variables or types called "in" in the value of the <xm:multiple> attribute will generate an error.

The following example is designed to operate on an incoming XML message like the preceding example. In this example, the <xm:multiple> attribute specifies that the contents of the <patID> and <numberOfItems> elements should be added as members of the serialNumber and quantity arrays.

    /**
     * @jws:operation
     * @jws:parameter-xml xml-map::
     * <placeOrder>
     * <order>
     *      <part xm:multiple="String serial in serialNumber, int quant in quantity">
     *         <partID>{serial}</partID>
     *         <numberOfItems>{quant}</numberOfItems>
     *      </part>
     * </order>
     * </placeOrder>
     *      * ::
     */
    public void placeOrder(String[] serialNumber, int[] quantity)
    {
          for (int i = 0; i < serialNumber.length; i++)
          {
            System.out.println("Ordered " + quantity[i] + " of part " + serialNumber[i]);
          }
    }

Note The xm prefix and its URI are declared implicitly in any JWS file. However, you must declare the namespace prefix and URI to use the prefix in XMLMAP files. You may change the prefix by declaring another prefix.

Related Topics

Handling Repeating XML Values with <xm:multiple>