1.0.5 • Published 6 years ago

chend-xml2json v1.0.5

Weekly downloads
3
License
MIT
Repository
github
Last release
6 years ago

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": [{}]
        }
    }
1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago