Git Product home page Git Product logo

xml2json's Introduction

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文件

<?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>

Javascipt文件

    xml2json('static/read.xml').then(res => {
        console.log(res) // res为转化后的JSON数据
    }).catch(e => {
        console.log(e)
    })

注意:采用npm安装组件需在项目中引入

  • import xml2json from 'chend-xml2json';

res返回的数据格式

    {
        "note": {
            "body": [{
                attrs: {
                    "by": "msg"
                }
            }],
            "from": [{
                attrs: {}
            }],
            "heading": [{
                "attrs": {},
                "children": {
                    "title": [],
                    "subtitle": []
                }
            }],
            "body": [{
                attrs: {}
            }]
        }
    }

xml2json's People

Contributors

cdhahaha avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.