XML content

You can access XML data from either a post parameter or from the HTTP request content.

You access XML data in post parameter by calling request.postParams.<parameter name>.getAsXmlContent().

You access XML data in the request content by calling request.getAsXmlContent().

Calling either of these two functions will return an object of type XMLContent that provides methods to iterate over the XML content.

An example using an XMLContent object with the following XML.
<records>
    <record>
        <name>Test Record 1</name>
        <description>Test Record 1 Description</description>
    </record>
    <record>
        <name>Test Record 2</name>
        <description>Test Record 2 Description</description>
    </record>
</records>

To iterate through the XML, you can do the following.
var xmlContent = request.getAsXmlContent();
// This outer loop will iterate over all record elements
for (var xmlElementIter = xmlContent.getIterator(’/records/record’); xmlElementIter.hasNext(); ) {
    var xmlElement = xmlElementIter.next();
    // This inner look will iterate over all elements within each record element
    for (var childIter = xmlElement.getIteratorOverAllChildren(); childIter.hasNext(); ) {
        var childElement = childIter.next();
        var fieldname = childElement.getName();                
    }
}
By calling xmlContent.getIterator(‘/records/record’) you can iterate over the record elements by calling hasNext() to determine if there is another element with the path specified in the expression argument in the call to getIterator(). The next() method gives you the next element found matching the expression. An object of type XMLElement is returned.