1.0.0 • Published 8 years ago
chend-xml2json v1.0.0
xml2json
xml转化为json
安装
npm
命令行输入
npm install -save-dev chend-xml2json
script引用
获取组件源码, git地址
https://github.com/cdhahaha/xml2json.git创建一个.html文件,在项目中引入源码 lib 文件夹中的index.js
<script src="index.js"></script> 使用
DEMO
<?xml version="1.0" encoding="GB2312"?>
<note>
<to by="msg">George</to>
<from>John</from>
<heading>
<title>Reminder</title>
<subtitle>Subtitle</subtitle>
</heading>
<body>Don't forget the meeting!</body>
</note> import xml2json from 'chend-xml2json';
xml2json('static/read.xml').then(res => {
console.log(res) // res为转化后的JSON数据
}).catch(e => {
console.log(e)
})res返回的数据格式
{
"note": {
"body": [{
attrs: {
"by": "msg"
}
}],
"from": [{}],
"heading": [{
"children": {
"title": [],
"subtitle": []
}
}],
"body": [{}]
}
}