XML Parser

The XML parser is used for parsing incoming XML data using XPath. To use it set decoder to xml and use a valid XPath path in your schema’s source.

Any path starting with a dot (.) will be considered a relative path and use the parent schema’s source as the root.
If the parent schema has the array type it will resolve to an element of that array.

Example

Incoming data:

<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
  <channel>
    <title>Example</title>
    <link>https://www.example.com</link>
    <item>
      <title>Test 1</title>
      <link>https://www.example.com/test-1</link>
      <description>Some text...</description>
    </item>
    <item>
      <title>Test 2</title>
      <link>https://www.example.com/test-2</link>
      <description>Some text...</description>
    </item>
  </channel>
</rss>

Decoder configuration:

decoder: xml
schema:
  type: array
  source: //item
  items:
    type: object
    properties:
      channel:
        type: string
        source: //channel/title
      title:
        type: string
        source: ./title
      link:
        type: string
        source: ./link
      description:
        type: string
        source: ./description

Output:

- channel: Example
  title: Test 1
  link: https://www.example.com/test-1
  description: Some text...

- channel: Example
  title: Test 2
  link: https://www.example.com/test-2
  description: Some text...