在 talend 中将多级 xml 转换为 json

Convert multilevel xml to json in talend

代码如下:

<labels>
<label><id>1</id><name>Planet E</name><contactinfo>Planet E Communications P.O. Box 27218 Detroit, 48227, USA p: 313.874.8729 f: 313.874.8732 email: info AT Planet-e DOT net
 </contactinfo><profile>Classic Techno label from Detroit, USA. [b]Label owner:[/b] [a=Carl Craig].
</profile><data_quality>Needs Vote</data_quality><urls><url>http://planet-e.net</url><url>http://planetecommunications.bandcamp.com</url><url>http://www.discogs.com/user/planetedetroit</url><url>http://www.facebook.com/planetedetroit</url><url>http://www.flickr.com/photos/planetedetroit</url><url>http://plus.google.com/100841702106447505236</url><url>http://myspace.com/planetecom</url><url>http://myspace.com/planetedetroit</url><url>http://soundcloud.com/planetedetroit</url><url>http://twitter.com/planetedetroit</url><url>http://vimeo.com/user1265384</url><url>http://www.youtube.com/user/planetedetroit</url><url>http://en.wikipedia.org/wiki/Planet_E_Communications</url></urls><sublabels><label>Antidote (4)</label><label>Community Projects</label><label>Guilty Pleasures</label><label>I Ner Zon Sounds</label><label>Planet E Communications, Inc.</label><label>TWPENTY</label></sublabels></label>
 <label><id>2</id><name>Earthtones Recordings</name><contactinfo>Seasons Recordings
2236 Pacific Avenue
Suite D
Costa Mesa, CA  92627

tel: +1.949.574.5255
fax: +1.949.574.0255

email: &lt;a href="mailto:jthinnes@seasonsrecordings.com"&gt;jthinnes@seasonsrecordings.com&lt;/a&gt;
   </contactinfo><profile>California deep house label founded by Jamie Thinnes. Now defunct and continued as [l=Seasons Recordings].</profile> <data_quality>Correct</data_quality><urls><url>http://www.seasonsrecordings.com/</url></urls></label></labels>

我试过 twritejsonfield 但它不保留多级层次结构。请帮忙

我改用了外部库。 Json-lib。我一行接一行地传递 xml 并将其转换为 json 并将 json 保存在一个扩展名为 json 的简单文件中。