@flatfile/plugin-xml-extractor

中文文档
0.7.1发布于 2024/10/03ISCTypeScriptESM + CJS近 30 天下载 5365

A plugin for parsing .xml files in Flatfile.

原始使用文档
文档目录3 节
  1. Parameters
  2. Usage
  3. Additional Options

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>) => {},
  })
);

版本与发布记录

@flatfile/plugin-xml-extractor 共发布 38 个版本,首次发布于 2023/07/19;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.9.02024/11/082 年前
0.8.12024/11/022 年前
0.8.02024/10/302 年前
0.7.1latest2024/10/032 年前
0.7.02024/09/242 年前
0.6.22024/08/012 年前

关于 @flatfile/plugin-xml-extractor 的常见问题

@flatfile/plugin-xml-extractor 是什么?

A plugin for parsing .xml files in Flatfile.

如何安装 @flatfile/plugin-xml-extractor?

在项目目录运行 npm install @flatfile/plugin-xml-extractor,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@flatfile/listener(^1.1.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@flatfile/plugin-xml-extractor 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@flatfile/plugin-xml-extractor 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@flatfile/plugin-xml-extractor 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >= 16。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@flatfile/plugin-xml-extractor 可以商用吗?

@flatfile/plugin-xml-extractor 使用 ISC 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@flatfile/plugin-xml-extractor 的下载量有多少?

根据 npm 官方下载统计,@flatfile/plugin-xml-extractor 在 2026/10/15 – 2026/11/13 这 30 天内被下载 5,365 次,日均约 179 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@flatfile/plugin-xml-extractor 还在维护吗?

最新版本 0.7.1 发布于 2024/10/03(2 年前);至今共发布 38 个版本,其中过去 12 个月发布了 0 个;首次发布于 2023/07/19。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。