You are viewing limited content. For full access, please sign in.

Question

Question

Workflow activity "Read XML" have a challenge to overcome.

asked on February 19, 2014

I have a challenge using the Read XML action in workflow.

The action works very well if I have a single node with multiple attributes but...  When the xml contains several nodes, all with the same title / attributes the action gets very complicated.

 

An example of the xml file is...

<?xml version="1.0" encoding="utf-16"?>

<Persons>

    <Data version="1.0"

last_name="JONES"

first_name="MATTHEW"

middle_name="DAVID"

     </Data>

     <Data version="1.0"

last_name="SMITH"

first_name="TERRY"

middle_name="ALLAN"

     </Data>

     <Data version="1.0"

last_name="MILLER"

first_name="DAVID"

middle_name="JACOB"

     </Data>

</Persons>

 

In the action "Read XML" I can use the xpath //@last_name|//@first_name|//@middle_name 

The options are "first match only" which works but I need to continue through the data and create records for each set.

another option is "All matches (combined with no spaces)"  and finally a third option of "All matches (as a multi value token)"

 

the option of "All matches (as a multi value token)" seemed to be the method of choice for this action as all the data meeting the criteria is returned to the token.

 

I then thought I could use the "For each value" action against the token but the data is not stored in the token as a collection, rather, each piece of data is stored individually in the multi value token.

Example of the token.

Token1

Field1 = JONES

Field2 = MATTHEW

Field3 = DAVID

Field4 = SMITH

Field5 = TERRY

Field6 = ALLAN

etc....

 

So my challenge is to use the data collected from the Read XML action to create other tokens for use in creating documents and template data but I need assistance with a setup that can process through each "Data" node as a collection.

0 0

Answer

APPROVED ANSWER
replied on February 19, 2014 Show version history

You’re on the right track with your Read XML activity. I do want to point out that the XML you supplied was missing closing brackets after your Data attribute; all of my advice down below uses the corrected XML instead of what was in the email. If you copied and pasted it, you may want to check to make sure your source is providing valid XML.

 

Your XPath string was “//@last_name|//@first_name|//@middle_name”, which returns all first, last and middle names. When you insert them into a multi-value field, you get a fairly messy collection of data. While it’s possible to work with a collection like that, it’s much easier to create three separate multi-value tokens: last name, first name, and middle name. Each token would have an XPath expression similar to “//@last_name”. Then you can iterate through all three tokens at the same time, using the token editor to get the value at a specified index.

 

Here is an example of a “For Each Value" activity, configured to iterate through the multi-value “Last Name” token, followed by “Assign Field Values”, configured to use this iteration’s last name value. I’m only working with the last name, but middle and first would work the exact same way.

 

This is the "For Each Value" activity, configured to run through the values in your multi-value token.

 

This is the configuration for “Assign Field Values”. I’m using the "First Name" and “Last Name”  tokens, but in the token editor, I edited them so that we're using the value at a specific index: the value of the “Iteration” token from the "For Each Value" activity.

 

Note that I’m assuming that there will always be a last, middle, and first name; if this isn’t true, there’s no guarantee that, say, the third entry in the “last name” token will correspond with the third entry in the “first name” token, and you’ll have to approach the problem a little bit differently.

0 0

Replies

You are not allowed to reply in this post.
You are not allowed to follow up in this post.

Sign in to reply to this post.