我正在使用Apache Kafka读取多个xml文件。我想将xml文件转换为平面文件(csv文件或文本文件)。我有一个输出如下:Xml解析Apache Kafka
我认为将xml转换为dom是一种解决方案或使用Jackson-xml数据转换器?
任何人都可以评论最好的解决方案来实现这一目标吗?谢谢!
输入1:
<?xml version="1.0" encoding="UTF-8"?>
<customer>
<id>123</id>
<firstName>Jane</firstName>
<phoneNumbers type="work">555-1111</phoneNumbers>
</customer>
输入2:
<?xml version="1.0" encoding="UTF-8"?>
<customer>
<id>1234</id>
<firstName>Bob</firstName>
<phoneNumbers type="work">555-1111</phoneNumbers>
</customer>
输出:
<?xml version="1.0" encoding="UTF-8"?><customer><id>123</id><firstName>Jane</firstName><phoneNumbers type="work">555-1234</phoneNumbers></customer>
<?xml version="1.0" encoding="UTF-8"?><customer><id>1234</id><firstName>Bob</firstName><phoneNumbers type="work">555-1111</phoneNumbers></customer>
哦有趣的解决方案。如何在不对每个字段进行硬编码的情况下遍历整个系列的xml?真正的文件非常长,并且有很多字段。 – Defcon
我会尝试使用xpath来获取一个节点的所有名称,并对其进行迭代。 –