Skip to content

Basic example

Bart Noordervliet edited this page Mar 24, 2022 · 6 revisions

In this example we'll convert this simple XML document containing information about books. The configuration YAML might look like this:

name: books
file: books.dump
path: /catalog/book
cols:
 - name: id
   path: /
   attr: id
 - name: author
   path: /author
 - name: title
   path: /title
 - name: genre
   path: /genre
   incl: ^(Fantasy|Science Fiction)$
 - name: price
   path: /price
 - name: publish_date
   path: /publish_date
 - name: description
   path: /description
   trim: true

So what we're saying here is that the table is called 'books', we want to write the output to the file 'books.dump'. The repeating XML element is <book> within the root <catalog> element. We take the id number from the 'id' attribute on the <book> element. Because this is the repeating element itself, the path for this column is empty. Then we take the other column values from the other elements within <book>. We put a regex filter on the 'genre' column to include only the Fantasy and Science Fiction genres. Finally we use the trim option on the description, because the XML file has linebreaks in it for readability that we don't want in the actual output.

Clone this wiki locally