@flatfile/plugin-xml-extractor

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

在 Flatfile 中解析.xml 文件的插件 .

中文使用文档
文档目录3 节
  1. 参数
  2. 使用量
  3. 附加选项

这个 @flatfile/xml-extractor 插件旨在从中提取结构化数据 XML 文件 。 它利用各种库来解析 XML 文件并检索 高效率地提供结构化数据.

事件类型 : listener.on('file:created')

支持的文件类型 : .xml

嵌入Flatfile时,该插件应被部署在服务器侧听器中. 学多点

参数

separator - 说吧 string - 说吧 default="/" - (可选)

加入或平整嵌入式属性时使用的分隔符.

options.chunkSize - 说吧 default="10_000" - 说吧 number - (可选)

这个 chunkSize 参数允许您指定要输入的记录数量 每个块.

options.parallel - 说吧 default="1" - 说吧 number - (可选)

这个 parallel 参数允许您指定要处理的块数 平行进行.

在此之前:

<?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>

之后:

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

attributePrefix - 说吧 string - 说吧 default: "#" - (可选)

平整 XML 标记属性时使用的前缀 .

在此之前:

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

之后:

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

transform - 说吧 (row) => Record<string, any> - (可选)

一个可以取出一行并返回已转换行的函数。 这对 在装入Flatfile之前调整数据.

在此之前:

<?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>

听众.js

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

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

之后:

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

使用量

听好要上传到 Flatfile 的 XML 文件 。 然后平台会自动取出文件. 一旦完成,文件将准备在文件区域导入 .

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

听众.js

listener.use(XMLExtractor());

附加选项

提取器可以接受额外的属性. props将会被传递到 Sheet.js 解析引擎.

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 是什么?

在 Flatfile 中解析.xml 文件的插件 .

如何安装 @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 和提交记录判断。