Read XML

Read XML activity

This activity retrieves values from an XML document using XPath expressions and stores the values in tokens that you can use elsewhere in your workflow. The XML document can be an XML file, such as a file stored in the repository, or XML text, such as the response from a web service. Learn about the tokens this activity produces.

Example: Vendors send each invoice as a PDF with a companion XML data file, and both are stored in the repository. A Download Electronic Document activity downloads the XML file, a Read XML activity extracts the invoice number, vendor name, and amount from it, and an Assign Field Values activity populates the invoice's metadata with those values.

Example: A Run Web Request Rule activity calls a web service that returns an XML response containing a Laserfiche document ID. A Read XML activity can retrieve the document ID from the response so you can use it in a later step in the workflow.

Note: The Read XML activity supports XPath 1.0.

To set up this activity:

  1. Drag the activity from the toolbox pane and drop it in the Designer pane.
  2. In the properties pane, type a name and description of the activity.
    The name and description editors
  3. In the XML Source property box, specify the XML document you want to process. Click the Token button (right arrow) Right arrow to add a token from an earlier activity in the workflow. You can use a file token or a text token:
    • File: To read an XML file, configure an activity that retrieves files earlier in the workflow, such as a Download Electronic Document activity, and select the token that contains the file, such as the Result File token.
    • Text: To read XML text, select a token that contains the XML, such as the Response Content token of a Run Web Request Rule activity.
  4. In the XPath Expression Tokens property box, click New Token... to open the Create New Expression dialog box.
  5. Next to Token Name, type a name for the token.
  6. Next to XPath Expression, type an XPath expression that traverses the XML document and selects the values you want. Click the Token button (right arrow) Right arrow to add a token, or click the Edit button Edit button to help you build the XPath expression.

    Example: The XPath expression //Document/@id selects the value of the id attribute on every Document element in the XML document.

  7. Choose where to store the result:
    • Create a token: Stores the result in a new token with the name you specified.
    • Update token: Stores the result in an existing token. Click the Token button (right arrow) Right arrow to select the token.
  8. In the drop-down under If multiple matches are found, return, specify what the activity returns when the XPath expression matches more than one node in the XML document. For example, select First match only to return only the first matching value.
  9. Optional: Click Click here to test the expression to validate your XPath expression. In the Test Input text box, paste or type a sample XML document of up to 20,000 characters. The values your XPath expression selects from the sample appear under Result. Click Clear inputs to start over.

    Note: The sample must be valid XML and no longer than 20,000 characters. If your XML document is longer, paste only the part that contains the elements your expression selects, and make sure it is still valid XML, with matching closing tags and any namespace declarations your expression uses. Text past 20,000 characters is cut off and a warning appears.

  10. Click OK.

In the XPath Expression Tokens property box, you can continue to edit the token by clicking the Edit button Edit button or delete the token by clicking the Delete button Delete button.

XML Namespaces

If your XML document uses namespaces, you can define prefix-namespace mappings and automatically clear default namespace declarations. This lets you write XPath expressions without using wildcards to match namespaces.

Example: An XML document contains the namespace declaration xmlns:LF="http://laserfiche.com/namespaces/importengine". After you map the LF prefix to the http://laserfiche.com/namespaces/importengine namespace, you can write an XPath expression that uses the prefix, such as //LF:ElementName/@AttributeName.

To configure XML namespaces:

  1. Select the Read XML activity in the designer pane.
  2. At the bottom of the properties pane, click Set XML Namespaces to open the XML Namespace Options dialog box.
  3. In the left column, type the prefix. In the right column, type the namespace associated with the prefix.

    Tip: Click Autodetect namespaces and provide a sample XML document that contains the namespace declarations you want. The activity populates the mappings automatically. The sample must be valid XML that includes the namespace declarations you want, and no longer than 20,000 characters. Text past the limit is cut off and a warning appears.

  4. Select Automatically clear default namespaces to remove default namespace declarations from the XML source document before the activity evaluates your XPath expressions.
  5. Click OK.

The namespaces you configure appear at the bottom of the activity's properties pane.

Migrating Self-Hosted Workflows

Workflows exported from self-hosted Laserfiche Workflow that contain the Read XML activity can be imported into Laserfiche Cloud and run without reconfiguring the activity. After you import a workflow, review the activity's XML Source property box to make sure it references an activity or token that is available in Laserfiche Cloud, such as a Download Electronic Document or Run Web Request Rule activity.

You may want to disable activities if you only want to test specific sections of your workflow. To disable activities:

  1. Select an activity in the designer pane to highlight it.
  2. In the Description property box, clear Enable.

Tokens for Read XML Activity

This activity produces a custom token for each XPath expression token you create with the Create a token option. The token contains the value or values the XPath expression selects from the XML document. Depending on the option you select under If multiple matches are found, return, the token can contain a single value or multiple values. If you select the Update token option, the activity stores the result in the existing token you selected instead.