Table of Contents

How to parse an XML document

Summary

Responses received from many types of connector rules are typically in the form of an XML document. The contents of these documents can be parsed into Process Commander properties.

In this example, a connector which returns conversion rates for two currencies has been manually created. The returned content from this connecter is structured as follows:

<GetRatesResponse xmlns="http://websevriceshare.com/"> <GetRatesResult>
<CurrencyFrom>
<Amount>1</Amount>
<CurrencyName>Canadian Dollar</CurrencyName>
<CurrencyShortName>CAD</CurrencyShortName>
</CurrencyFrom>
<CurrencyTo>
<CurrencyToRow>
<Amount>0.8016</Amount>
<CurrencyName>U.S. Dollar</CurrencyName>
<CurrencyShortName>USD</CurrencyShortName>
<LastUpdated>2009-02-12T00:00:00</LastUpdated>
</CurrencyToRow>
</CurrencyTo>
</GetRatesResult> </GetRatesResponse

It is recommended to use the Parse rules created by an accelerator.

 

Suggested Approach

To parse an XML document with Parse XML rules:

  1. For each returned XML element, create a corresponding property. The structure of the properties should match the structure of the XML document. For example, using the XML snipped above, the properties should be created as follows:
    Properties
  2. Create a new Parse XML rule by navigating to the Integration-Mapping category and selecting Parse XML. Complete the New Rule Dialog. Set the Root Name Element field to the name of the property under which the rest of the properties appear (GetRatesParametersResponse in this example).
    Parse
  3. Open the Mapping tab of the Parse XML form. Set the context of the root element. Double-click on the root node to access the Mapping Properties panel.
    Using the SmartPrompt, select the page containing the newly created properties (GetRatesParametersResult in this example). Click OK.
    Map Properties
  4. Using the Add element icon, add elements to the rule form according to the structure of the XML document. For Page properties, select the property in the element's Context Page field. For standard properties, select the property in the element's Property field.
    Tree Structure
    Note: To reorder elements added previously, select and drag the element. Drop it in the desired location in the tree.
  5. Test the Parse rule by clicking the Run button in the tool bar. In the Run Rule window, provide the XML source to be parsed and click the Execute button. The resulting properties will appear on the clipboard.
    test

50% found this useful

Have a question? Get answers now.

Visit the Collaboration Center to ask questions, engage in discussions, share ideas, and help others.