# 微信小程序之XML字符串解析为JavaScript对象
**Repository Path**: lihaogn/XML2JSObject
## Basic Information
- **Project Name**: 微信小程序之XML字符串解析为JavaScript对象
- **Description**: 在微信小程序中将xml字符串解析成JavaScript对象。
- **Primary Language**: Unknown
- **License**: Apache-2.0
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2019-07-26
- **Last Updated**: 2021-03-01
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# 微信小程序之XML字符串解析为JavaScript对象
#### 介绍
在微信小程序中将xml字符串解析成JavaScript对象。
示例代码地址:https://gitee.com/lihaogn/XML2JSObject
#### 使用说明
1. 核心文件
使用到了xmldom库:https://github.com/jindw/xmldom
```
/common/common.js
/lib/dom-parser.js
/lib/dom.js
/lib/entities.js
/lib/sax.js
```
2. 在页面中使用,以`page/index/index`为例
```javascript
//index.js
const app = getApp()
// ***** 需要引入外部js文件
var common = require('../../common/common.js');
Page({
data: {
},
onLoad: function () {
// xml字符串
var testxt =
'' +
'' +
'' +
'tom' +
'34' +
'' +
'' +
'jack' +
'12' +
'' +
'' +
'alice' +
'22' +
'' +
'' +
'' +
'test-txt' +
'' +
'';
// 你想解析的节点名
var baseNodeName='animals';
// 解析xml字符串,转换成js对象
var resObj=common.xml2Obj(testxt,baseNodeName);
console.log(resObj);
},
})
// 结果:
```
