github.com/Jeffail/benthos/v3@v3.65.0/website/docs/components/processors/xml.md (about)

     1  ---
     2  title: xml
     3  type: processor
     4  status: beta
     5  categories: ["Parsing"]
     6  ---
     7  
     8  <!--
     9       THIS FILE IS AUTOGENERATED!
    10  
    11       To make changes please edit the contents of:
    12       lib/processor/xml.go
    13  -->
    14  
    15  import Tabs from '@theme/Tabs';
    16  import TabItem from '@theme/TabItem';
    17  
    18  :::caution BETA
    19  This component is mostly stable but breaking changes could still be made outside of major version releases if a fundamental problem with the component is found.
    20  :::
    21  
    22  Parses messages as an XML document, performs a mutation on the data, and then
    23  overwrites the previous contents with the new value.
    24  
    25  
    26  <Tabs defaultValue="common" values={[
    27    { label: 'Common', value: 'common', },
    28    { label: 'Advanced', value: 'advanced', },
    29  ]}>
    30  
    31  <TabItem value="common">
    32  
    33  ```yaml
    34  # Common config fields, showing default values
    35  label: ""
    36  xml:
    37    operator: to_json
    38    cast: false
    39  ```
    40  
    41  </TabItem>
    42  <TabItem value="advanced">
    43  
    44  ```yaml
    45  # All config fields, showing default values
    46  label: ""
    47  xml:
    48    operator: to_json
    49    cast: false
    50    parts: []
    51  ```
    52  
    53  </TabItem>
    54  </Tabs>
    55  
    56  ## Operators
    57  
    58  ### `to_json`
    59  
    60  Converts an XML document into a JSON structure, where elements appear as keys of
    61  an object according to the following rules:
    62  
    63  - If an element contains attributes they are parsed by prefixing a hyphen,
    64    `-`, to the attribute label.
    65  - If the element is a simple element and has attributes, the element value
    66    is given the key `#text`.
    67  - XML comments, directives, and process instructions are ignored.
    68  - When elements are repeated the resulting JSON value is an array.
    69  
    70  For example, given the following XML:
    71  
    72  ```xml
    73  <root>
    74    <title>This is a title</title>
    75    <description tone="boring">This is a description</description>
    76    <elements id="1">foo1</elements>
    77    <elements id="2">foo2</elements>
    78    <elements>foo3</elements>
    79  </root>
    80  ```
    81  
    82  The resulting JSON structure would look like this:
    83  
    84  ```json
    85  {
    86    "root":{
    87      "title":"This is a title",
    88      "description":{
    89        "#text":"This is a description",
    90        "-tone":"boring"
    91      },
    92      "elements":[
    93        {"#text":"foo1","-id":"1"},
    94        {"#text":"foo2","-id":"2"},
    95        "foo3"
    96      ]
    97    }
    98  }
    99  ```
   100  
   101  With cast set to true, the resulting JSON structure would look like this:
   102  
   103  ```json
   104  {
   105    "root":{
   106      "title":"This is a title",
   107      "description":{
   108        "#text":"This is a description",
   109        "-tone":"boring"
   110      },
   111      "elements":[
   112        {"#text":"foo1","-id":1},
   113        {"#text":"foo2","-id":2},
   114        "foo3"
   115      ]
   116    }
   117  }
   118  ```
   119  
   120  ## Fields
   121  
   122  ### `operator`
   123  
   124  An XML [operation](#operators) to apply to messages.
   125  
   126  
   127  Type: `string`  
   128  Default: `"to_json"`  
   129  Options: `to_json`.
   130  
   131  ### `cast`
   132  
   133  Whether to try to cast values that are numbers and booleans to the right type. Default: all values are strings.
   134  
   135  
   136  Type: `bool`  
   137  Default: `false`  
   138  
   139  ### `parts`
   140  
   141  An optional array of message indexes of a batch that the processor should apply to.
   142  If left empty all messages are processed. This field is only applicable when
   143  batching messages [at the input level](/docs/configuration/batching).
   144  
   145  Indexes can be negative, and if so the part will be selected from the end
   146  counting backwards starting from -1.
   147  
   148  
   149  Type: `array`  
   150  Default: `[]`  
   151  
   152