MetricsHub
MetricsHub Community Connectors 1.0.22
-
Home
- Connector Developer Guide Computes 24
xml2Csv (Compute)
When To Use
Use xml2Csv to turn a raw XML payload — typically the body of an http[1] source that queries an XML API — into the tabular form that mapping and other computes expect. recordTag locates the repeating record elements in the document, and properties lists the values (child elements or attributes) to capture from each record: the compute emits one row per record, one column per property.
Like json2Csv for JSON payloads, it is almost always the first compute in the pipeline: convert to a table immediately, then reshape with regular table computes.
Syntax
sources:
fanInventory:
type: http
method: get
path: /api/inventory/fans
resultContent: body
computes:
- type: xml2Csv
recordTag: /inventory/fans
properties: fan>id;fan>speedRpm;fan>status
Properties
| Property | Required | Default | Description |
|---|---|---|---|
type |
Yes | None | xml2Csv. |
recordTag |
No | None | Slash-separated absolute path of the element under which the records are read (for example /inventory/fans). Use / to read records directly under the document root. |
properties |
Yes | None | Semicolon-separated list of value selectors, each resolved relative to recordTag. Use > to descend into nested elements (fan>speedRpm); a name matches the child element text or the attribute with that name. The list order defines the column order. |
Unlike json2Csv, xml2Csv does not prepend an extra entry column: the first selector in properties becomes column 1.
Table Transformation Example
Input (XML body)
<inventory>
<fans>
<fan id="fan-1" speedRpm="4200" status="ok"/>
<fan id="fan-2" speedRpm="3900" status="degraded"/>
</fans>
</inventory>
Result
| id (col 1) | speedRpm (col 2) | status (col 3) |
|---|---|---|
| fan-1 | 4200 | ok |
| fan-2 | 3900 | degraded |
Equivalent serialized output:
fan-1;4200;ok
fan-2;3900;degraded
Recommended Pattern
- Set
resultContent: bodyon the HTTP source and putxml2Csvfirst in itscomputespipeline. - Point
recordTagat the deepest element that encloses all records, then keep the selectors short (record>valuerather than long absolute paths). - Select a stable identifier (an
idor DN-style attribute) as the first property so later computes andmappingcan key on$1. - Follow up with
keepOnlyMatchingLinesorexcludeMatchingLineswhen the same container mixes several record types.
Common Mistakes
- Separating
propertieswith commas: the list is semicolon-separated. - Using
/inside a property selector:recordTaguses/for its path, but property selectors descend with>. - Pointing
recordTagat the record element itself when the selectors already start with that element name (the element would then be looked up one level too deep) — keeprecordTagon the parent container in that style. - Expecting a leading entry column as with
json2Csv: here the first captured property is$1.
Community Examples
No community connector currently uses xml2Csv; the examples above are illustrative.
- [1] ../sources/http.html
