xml - 如何在scala中单独处理大xml有效负载的块
问题描述
我有很大的 xml 有效负载,我有时会得到/我得到它如下(示例)
<items>
<item>
<property>1</property>
<property2>2</property2>
<nested-property>
<property>1</property>
</nested-property>
</item>
<item>
<property>1</property>
<property2>2</property2>
<nested-property>
<property>1</property>
</nested-property>
</item>
<item>
<property>1</property>
<property2>2</property2>
<nested-property>
<property>1</property>
</nested-property>
</item>
<item>
<property>1</property>
<property2>2</property2>
<nested-property>
<property>1</property>
</nested-property>
</item>
...
...
...
现在我需要每次选择 n 个元素并将它们发送到下游系统,我如何在 scala 中执行此操作?
解决方案
找到更简单的方法来做到这一点......
xmlData = XML.loadString(paylaod)
val = xmlData \ "items" \ "item"
chunkSize = 50
xmlData.toList.grouped(chunkSize)
.toList.map(list => "<items>" + list.mkString("") + "</items>")
.toNel
现在我有一个分块 xml 的列表,我以后可以处理每个分块/分组的数据。虽然有点太粗略的解决方案
在此链接上找到了分组解决方案 如何将集合分成批次?
推荐阅读
- c#-4.0 - 如果主要服务失败并在顶层恢复,如何重新启动依赖服务
- python - 如何修复此错误:[WinError 267] 目录名称无效:
- php - PHP 准备好的语句;奇怪的结果
- java - netty 测试:如何向处理程序发送帖子
- jquery - 再次调用jQuery时防止默认创建问题
- maven - 在 Eclipse 中创建原型时出错
- javascript - .net Core 2.0 文件上传大小限制
- java - 在 doPost 方法中的 URL 内发送 JSONString,JAVA
- compilation - STM32 位置无关二进制文件
- amazon-web-services - AWS GreenGrass 检查 Lambda 中的主题