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

Question

Question

Read XML Help

asked on August 25, 2016

Hi guys. Not the best at parsing XML data using Workflow's Read XML activity and was wondering if someone could help point me in the right direction. I have the following XML and need to be able to pick out specific rows based on  the Field ID value and retrieve the Value value from that row. For the STExpectFirstName and STEExpectLastName Field ID's, the beginning of those can change, but FirstName and LastName will always be part of the Field ID. On those 2, how would I just look for those two parts of the Field ID to make the match on? Thanks in advance for your help.

<?xml version="1.0" encoding="UTF-8"?>
<FormImageMeta>
<FormImage>
<Form FormID="StoreExpectBoard" Ver="1.2" CreateDate="08-25-2016111912" CreatedAt="59" CreatedBy="null" PageNumber="0" />
<ImageProperties Type="tif" File="StoreExpectBoard-08-25-2016111912.tif" />
</FormImage>
<Reference_Data>
<Field Field_ID="StoreExpectPg4StoreNumTextField" DataType="String" Value="0059" />
<Field Field_ID="StExpecSSNTxtField" DataType="String" Value="555663141" />
<Field Field_ID="StExpectFormNameTEXTFIELD" DataType="String" Value="StoreExp" />
<Field Field_ID="STExpectFirstName" DataType="String" Value="mickey" />
<Field Field_ID="STExpectLastName" DataType="String" Value="mouse jr" />
</Reference_Data>
</FormImageMeta>

 

1 0

Replies

replied on August 26, 2016 Show version history

Hi Blake,

You can use this XPath selector to get the value for the desired nodes:

//Field[@Field_ID='STExpectFirstName']/@Value

Here's a breakdown of what's happening:

  • //Field: find any element named Field
  • [@Field_ID='STExpectFirstName']: of these elements named Field, find the (first one) with the Field_ID attribute that has a value of 'STExpectFirstName'
  • /@Value: now that we have the right node, select the value of the Value attribute

For future investigation, there is actually an XPath reference at W3Schools.

Hope this helps!

UPDATE:

Sorry, after posting I saw the distinction you had that the Field_ID values could change, but would always have 'FirstName' or 'LastName'. In that case, this should work:

//Field[contains(@Field_ID,'FirstName')]/@Value

This will look for any Field elements, with a Field_ID attribute whose value contains the string 'FirstName', then return the value of the Value attribute for that Field element.

I've left the original post though, in case someone in future needs a less-variable way to achieve the same thing.

1 0
replied on August 26, 2016

Upon further reflection, you can do better maybe by replacing the contains function with the ends-with function, if the Field_ID is always of the form '[prefix]FirstName'.

0 0
replied on August 26, 2016

If those field will always be in that order you can actually just refer to them by number and you won't have a problem with field names changing.

 

For example to get first name you could use this

/FormImageMeta/Reference_Data//Field[4]/@Value

From testing it I get the value "mickey"

0 0
replied on August 26, 2016

Unfortunately the order can change depending on other factors within the software that creates the XML.

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

Sign in to reply to this post.