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