0.5.16 • Published 18 days ago

@flatfile/plugin-xml-extractor v0.5.16

Weekly downloads
-
License
ISC
Repository
github
Last release
18 days ago

The @flatfile/xml-extractor plugin is designed to extract structured data from XML files. It utilizes various libraries to parse XML files and retrieve the structured data efficiently.

Event Type: listener.on('file:created')

Supported file types: .xml

When embedding Flatfile, this plugin should be deployed in a server-side listener. Learn more

Parameters

separator - string - default="/" - (optional)

The separator to use when joining or flattening nested attributes.

options.chunkSize - default="10_000" - number - (optional)

The chunkSize parameter allows you to specify the quantity of records to in each chunk.

options.parallel - default="1" - number - (optional)

The parallel parameter allows you to specify the number of chunks to process in parallel.

Before:

<?xml version="1.0" encoding="utf-8" ?>
<root>
    <person>
        <name>John</name>
        <age>30</age>
        <country>
            <name>USA</name>
            <code>US</code>
        </country>
    </person>
</root>

After:

[
  {
    "name": "John",
    "age": "30",
    "country/name": "USA",
    "country/code": "US"
  }
]

attributePrefix - string - default: "#" - (optional)

The prefix to use when flattening attributes of XML tags.

Before:

<?xml version="1.0" encoding="utf-8" ?>
<root>
    <person>
        <name>John</name>
        <age>30</age>
        <country code="US">USA</country>
    </person>
</root>

After:

[
  {
    "name": "John",
    "age": "30",
    "country": "USA",
    "country#code": "US"
  }
]

transform - (row) => Record<string, any> - (optional)

A function that takes a row and returns a transformed row. This is useful for adjusting the data before it is loaded into Flatfile.

Before:

<?xml version="1.0" encoding="utf-8" ?>
<root>
    <person>
        <name>John</name>
        <age>30</age>
        <country code="US">USA</country>
    </person>
    <person>
        <name>Jane</name>
        <age>25</age>
        <country code="CA">Canada</country>

    </person>

</root>

listener.js

import { XMLExtractor } from "@flatfile/plugin-xml-extractor";

export default (listener) => {
  listener.use(
    XMLExtractor({
      transform: (row) => {
        return {
          ...row,
          age: parseInt(row.age),
        };
      },
    })
  );
};

After:

[
  {
    "name": "John",
    "age": 30,
    "country": "USA",
    "country#code": "US"
  },
  {
    "name": "Jane",
    "age": 25,
    "country": "Canada",
    "country#code": "CA"
  }
]

Usage

Listen for an XML file to be uploaded to Flatfile. The platform will then extract the file automatically. Once complete, the file will be ready for import in the Files area.

npm i @flatfile/plugin-xml-extractor
import { XMLExtractor } from "@flatfile/plugin-xml-extractor";

listener.js

listener.use(XMLExtractor());

Additional Options

The extractor can accept additional properties. Props will be passed along to the Sheet.js parsing engine.

listener.use(
  XMLExtractor({
    separator: "/",
    attributePrefix: "#",
    transform: (row: Record<string, any>) => {},
  })
);
0.5.16

18 days ago

0.5.15

26 days ago

0.5.14

1 month ago

0.5.13

3 months ago

0.5.12

4 months ago

0.5.11

5 months ago

0.5.10

5 months ago

0.5.9

5 months ago

0.5.8

6 months ago

0.5.7

7 months ago

0.5.6

7 months ago

0.5.5

7 months ago

0.5.4

8 months ago

0.5.3

8 months ago

0.5.2

8 months ago

0.5.1

8 months ago

0.5.0

8 months ago

0.4.0

9 months ago

0.3.3

9 months ago

0.3.2

9 months ago

0.3.1

9 months ago

0.3.0

9 months ago

0.2.0

9 months ago

0.1.0

10 months ago

0.0.2

10 months ago

0.0.1

10 months ago