"xml转化为json,多谢": 多谢 xml转化为json,谢谢
需要对xml文件中的信息进行提取,代码如何实现,谢谢。
xml文件如下:xml code
<book>
<bookstate>ok</bookstate>
<bookshelf id="1" shelfinfo="shelfinfoa" pid="0" slevel="1" shelfname="书架1" />
<bookshelf id="2" shelfinfo="shelfinfo2" pid="1" slevel="2" shelfname="科普书架" >
<bookinfo bookinfo='ssss' bookname="地球人" bookid="1002" />
<bookinfo bookinfo='dddd' bookname="火星人" bookid="1003" />
<bookinfo bookinfo='aaaa' bookname="水星人" bookid="1004" />
<bookinfo bookinfo='ffff' bookname="土星人" bookid="1005" />
</bookshelf>
<bookshelf id="3" shelfinfo="shelfinfo3" pid="1" shelfname="历史书架" />
<bookshelf id="4" shelfinfo="shelfinfob" pid="3" shelfname="中文历史书架" />
<bookshelf id="5" shelfinfo="xxshelfinfo" pid="4" shelfname="近代中文历史书架" />
<bookshelf id="7" shelfinfo="shelfinfo22" pid="1" shelfname="文学书架" >
<bookinfo bookinfo='eeeec' bookname="古代诗词" bookid="1001" />
</bookshelf>
<bookshelf id="9" shelfinfo="shelfinfow" pid="7" shelfname="古代文学书架" />
</book>
最后提取的信息组合为:
{id:1,info:'shelfinfoa',pid:0,name:'书架1'},
{id:2,info:'shelfinfo2',pid:1,name:'科普书架'},
{id:1002,info:'ssss',pid:2,name:'地球人'},
{id:1003,info:'dddd',pid:2,name:'火星人'},
{id:1004,info:'aaaa',pid:2,name:'水星人'},
{id:1005,info:'ffff',pid:2,name:'土星人'},
{id:3,info:'shelfinfo3',pid:1,name:'历史书架'},
{id:4,info:'shelfinfob',pid:3,name:'中文历史书架'},
{id:5,info:'xxshelfinfo',pid:4,name:'近代中文历史书架'},
{id:7,info:'shelfinfo22',pid:1,name:'文学书架'},
{id:1001,info:'eeeec',pid:7,name:'古代诗词'},
{id:9,info:'shelfinfow',pid:7,name:'古代文学书架'}
------解决方案--------------------
简单的方法,遍历xml进行拼接输出就可以了
或者找一些现成的
如
------解决方案--------------------