Special Formatters

Version 20.0.7488


Special Formatters

Version 20.0.7488


The following is a list of formatters that are used in conjunction with operations that parse XML and CSV. Examples of each formatter are provided at the bottom of the page.

xpath(value)

The XPath formatter can be used inside calls to XML operations that have the XML DOM available. The xmlDOMSearch and xmlDOMGet operations are used to parse an XML document and the XPath formatter is a formatter of the DOM object that functions like other formatters by generating the values from an XML document. The XPath formatter returns the current XPath location of an XML document.

  • value: The optional string of a relative XPath to find the associated XML value from.

csv(value)

The CSV formatter can be used after loading the data from a CSV file. The csvListRecords operation is used to parse a CSV file and the CSV formatter is a formatter of the CSV data that functions like other formatters by generating the values from a CSV document.

  • value: The string of a CSV column header to find the values from that column. Note that if the CSV file does not have headers, columns can be accessed by a generic index (c1, c2, c3, …) instead if the ‘requireheader’ attribute is set to false.

[csv(value) | csvescape()]

The csvescape formatter returns the CSV data from the column that matches a value with each element output as individual results.

Examples

xpath

In the following snippet, an XML document is defined in memory in ArcScript.

<arc:set attr="text">
  <root>
    <A>Value_One</A>
    <A>
      <B>
        <C>Value_Two</C>
      </B>
    </A>
    <A>
      <B>Value_Three</B>
    </A>
  </root>
</arc:set>

In the following snippet, the xmlDOMSearch operation is called and XPath formatters are displayed from the sample XML document.

<arc:call op="xmlDOMSearch?xpath=/root/A">
  Current XPath is [xpath] and the 'B' element value is [xpath(B) | empty("not present")]
</arc:call>

Run against the preceding XML document, this code would display the following output.

Current XPath is /root/A[1] and the 'B' element value is not present
Current XPath is /root/A[2] and the 'B' element value is not present
Current XPath is /root/A[3] and the 'B' element value is Value_Three

In the previous example, the XPath formatter displays the three A elements that are iterated over. But only Value_Three from the final B element is displayed as [xpath(B)] ignores the values in other elements.

csv and csvescape

In the following snippets, a CSV document is defined in memory in ArcScript.

<arc:set attr="data" value=
"column1,column2,column3
entry1,entry2,entry3
entry4,entry5,entry6"
/>

In the following example, the csvListRecords operation is called and CSV formatters are displayed from the sample CSV document.

<arc:call op="csvListRecords">
Row [_index] values: [csv('column1')], [csv('column2')], [csv('column3')]
</arc:call>

This code would display the following output:

Row 1 values: entry1, entry2, entry3
Row 2 values: entry4, entry5, entry6

In the following example, both the CSV formatter and the csvescape options are output from the sample CSV document.

<arc:call op="csvListRecords">
Standard output: [csv('column1')], [csv('column2')], [csv('column3')]
Output with csvescape(): [csv('column1') | csvescape()], [csv('column2') | csvescape()], [csv('column3') | csvescape()]
</arc:call>

This code would display the following output for the first row under the CSV headers.

Standard output: entry1, entry2, entry3
Output with csvescape(): "entry1", "entry2", "entry3"