当我尝试通过一些在线工具将以下格式的复杂XML转换为CSV文件时,它提供了多个csv文件?这是将所有以下XML元素及其属性转换为多个CSV的唯一方法吗?或者是否可以使用xml中的所有以下元素和属性创建一个csv文件?
示例XML:
<messages>
<message messageID="12345" orderNumber="1111111" model="AA" tls="22222" status="99" timestamp="2014-04-25 08:27:17Z">
<attributes>
<attribute name="aaaaaaaaaa" value="ff" />
<attribute name="bbbbbbbb" value="L.f" />
<attribute name="ccccccccc" value="333" />
<attribute name="ddddddddd" value="n.998" />
</attributes>
</message>
<message messageID="12345" orderNumber="1111111" model="AA" tls="22222" status="99" timestamp="2014-04-25 08:27:17Z">
<attributes>
<attribute name="yyyyyyy" value="j8" />
<attribute name="jjjjjjjjjj" value="L.O" />
<attribute name="mmmmmmm" value="33333" />
<attribute name="nnnnnnnn" value="K.9999" />
</attributes>
</message>
</messages>
答案 0 :(得分:0)
XML看起来像是适当的格式,因为它是嵌套数据。您也可以使用JSON或YAML。将数据放入单个CSV文件的唯一机会是将<attributes>
展平为如下字符串:
(aaaaaaaaaa;ff)(bbbbbbbb;L.f)...
但是,除非您的数据不包含()
和;
,否则这只会有效 - 或者除非您找到其他有效的分隔符。
然后CSV看起来像:
messageID,orderNumber, ... ,attributes
12345,1111111, ... ,(aaaaaaaaaa;ff)(bbbbbbbb;L.f)...
但这是黑客攻击,常见的CSV解析器无法理解。但是,如果您可以控制其他站点上的CSV编写器和解析器,则可以使用它。但是,为什么不使用XML(或JSON,YAML)?
答案 1 :(得分:0)
尝试: http://www.deeppay.net/sepa/sepa2csv.html
它会让你扁平化。属性名称和值将在不同的列中通过:
"type",".../@timestamp",".../@status",".../message/@tls",".../@model",".../@orderNumber",".../@messageID",".../attribute[3]/type",".../attribute[3]/$",".../attribute[3]/.../@value",".../attribute[3]/.../@name",".../attribute[2]/type",".../attribute[2]/$",".../attribute[2]/.../@value",".../attribute[2]/.../@name",".../attribute[1]/type",".../attribute[1]/$",".../attribute[1]/.../@value",".../attribute[1]/.../@name",".../attribute[0]/type",".../attribute[0]/$",".../attribute[0]/.../@value",".../attribute[0]/.../@name" "/messages/message","2014-04-25 08:27:17Z","99","22222","AA","1111111","12345","/messages/message/attributes/attribute","","n.998","ddddddddd","/messages/message/attributes/attribute","","333","ccccccccc","/messages/message/attributes/attribute","","L.f","bbbbbbbb","/messages/message/attributes/attribute","","ff","aaaaaaaaaa" "/messages/message","2014-04-25 08:27:17Z","99","22222","AA","1111111","12345","/messages/message/attributes/attribute","","K.9999","nnnnnnnn","/messages/message/attributes/attribute","","33333","mmmmmmm","/messages/message/attributes/attribute","","L.O","jjjjjjjjjj","/messages/message/attributes/attribute","","j8","yyyyyyy"
答案 2 :(得分:0)
我从windows商店使用这个应用程序: https://www.microsoft.com/en-us/store/p/xml-into-csv/9p0qsrvjcsj5
答案 3 :(得分:0)