Skip to main content

Sometimes I find I need to find files passing through a flow based on their content.

To help with this, I grab some useful data and rename the file as it passes through the flow.

These I can use the search function in the Input and Output connector tabs.

 

<arc:set attr="xml.xpath" value="/" />
<arc:set attr="xml.uri" value=""Filepath]" />
<arc:call op="xmlDOMSearch" in="xml" out="result">
<!-- xpath is a context sensitive function in arcscript. If an xml document is loaded in a
search, xpath will return the name of a child relative to the search result -->
<arc:set attr="output.header:e_id" value=""xpath('/Schedule/Results/TrackingEvent/e_id')]" />
<arc:set attr="output.header:p_uuid" value=""xpath('/Schedule/Results/TrackingEvent/p_uuid')]" />
<arc:set attr="output.header:e_country_code" value=""xpath('/Schedule/Results/TrackingEvent/e_country_code')]" />
<arc:set attr="output.header:c_carrier_name" value=""xpath('/Schedule/Results/TrackingEvent/c_carrier_name')|replace(' ','')]" />
<arc:set attr="output.header:p_tracking_number" value=""xpath('/Schedule/Results/TrackingEvent/p_tracking_number')]" />
</arc:call>

<arc:set attr="output.FilePath" value=""FilePath]" />
<arc:set attr="output.filename" value=""output.header:e_id]--output.header:e_country_code]--output.header:p_tracking_number]--output.header:c_carrier_name]--output.header:p_uuid].xml" />
<arc:push item="output" />

 

Hi Russel,

You can use xmlDOMGet to map all the values from the XML node, save these in the header, and then apply them for the filename.

Here's a simple modified script (add other XPaths as needed):

<arc:set attr="xml.uri" value="[FilePath]" />
<arc:set attr="xml.map:e_id" value="Schedule/Results/TrackingEvent/e_id" />
<arc:set attr="xml.map:c_carrier_name" value="Schedule/Results/TrackingEvent/c_carrier_name" />
<arc:call op="xmlDOMSearch" in="xml" out="result">
<!-- xpath is a context sensitive function in arcscript. If an xml document is loaded in a
search, xpath will return the name of a child relative to the search result -->
<arc:set attr="output.header:e_id" value="[result.e_id]" />
<arc:set attr="output.header:c_carrier_name" value="[result.c_carrier_name |replace(' ','')]" />
</arc:call>

<arc:set attr="output.FilePath" value="[FilePath]" />
<arc:set attr="output.filename" value="[output.header:e_id]-[output.header:c_carrier_name].xml" />
<arc:push item="output" />

More on xmlDOMGet: https://cdn.cdata.com/help/AZK/mft/op_XMLDOMGet.html


If you want to Get the date from the XML file from the XPaths, you use the xmlDOMGet operation to get the data from the specified XPath and then use those data to rename the filename, You can use this example we have on our help on how to get the data from the XML file and add it as a header to the file with an additional <arc:set> to rename the filename.

 

I just added a condition to rename the filename as shown below, we need use the map:* to call the xmlDOMGet operation to Get the values from the specific XPath: Below is the modified ArcScript:

 

Note: 

  • map:*: A set of one or more inputs where the name of the mapped parameter precedes the colon (for example, map:foo), and the value is the xpath to the desired xml element in the document. See Examples for more information in the help document - CData Arc - xmlDOMGet | Version 24.2.8965


 

<!-- Setting the input uri and map parameters -->
<arc:set attr="xml.uri" value=""Filepath]" />
<arc:set attr="xml.map::e_id" value="/Schedule/Results/TrackingEvent/e_id" />
<arc:set attr="xml.map::p_uuid" value="/Schedule/Results/TrackingEvent/p_uuid" />
<arc:set attr="xml.map::e_country_code" value="/Schedule/Results/TrackingEvent/e_country_code" />
<arc:set attr="xml.map::c_carrier_nameInitial" value="/Schedule/Results/TrackingEvent/c_carrier_name" />
<arc:set attr="xml.map::p_tracking_number" value="/Schedule/Results/TrackingEvent/p_tracking_number" />

<!-- Calling the operation, passing in the xml item and creating a "result" output item -->
<arc:call op="xmlDOMSearch" in="xml" out="result">

<! The nameFinal attribute below holds the final name without space with the help of the replacement operation and the output.filename will give the expected output -->

<arc:set attr="c_carrier_nameFinal" value=""result.c_carrier_nameInitial | replace(' ','')]" />
<arc:set attr="output.filename" value=""result.e_id]-lresult.e_country_code]-rresult.p_tracking_number]-_result.c_carrier_nameFinal]-mresult.p_uuid].xml" />
</arc:call>

<arc:set attr="output.FilePath" value=""FilePath]" />
<arc:push item="output" />

 

Let us know if this helps.


Reply