https://github.com/riversun/xml2node
JavaScript Simple XML parser
https://github.com/riversun/xml2node
json parser xml
Last synced: about 2 months ago
JSON representation
JavaScript Simple XML parser
- Host: GitHub
- URL: https://github.com/riversun/xml2node
- Owner: riversun
- License: mit
- Created: 2018-07-09T11:17:27.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-07-20T02:21:19.000Z (almost 8 years ago)
- Last Synced: 2025-06-15T14:21:27.921Z (about 1 year ago)
- Topics: json, parser, xml
- Language: JavaScript
- Homepage:
- Size: 27.3 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Overview
'xml2node' is simple XML parser for javascript allows you to parse XML into JS and access values/attributes easily.
It is licensed under [MIT license](https://opensource.org/licenses/MIT).
# Quick start
## demo on the web
https://riversun.github.io/xml2node/
## demo on node.js
**clone this project and type**
```shell
git clone https://github.com/riversun/xml2node.git
npm start
```
## install via npm
```shell
npm install xml2node
```
# How to use?
## Access element of XML values/attributes like as follows.
### Example input-XML
```XML
Original Title
```
You can access XML values/attributes like this.
```JavaScript
var parser = new Xml2Node.Parser();
var jsObject = parser.parseXML(xmlText);
var node=new Xml2Node.Node(jsObject);
console.log(node.get("opml").attr("version")); // -> 2.0
console.log(node.get("opml").get("head").get("title").value()); // ->Original Title
console.log(node.get("opml").get("body").get("outline",0).attr("text")); // -> Greeting
console.log(node.get("opml").get("body").get("outline",0).get("outline",0).attr("text")); // -> We say good morning in the morning.
console.log(node.get("opml").get("body").get("outline",0).get("outline",1).attr("text")); // -> We say hello at noon.
console.log(node.get("opml").get("body").get("outline",0).get("outline",2).attr("text")); // -> We say good evening at night.
console.log(node.get("opml").get("body").get("outline",1).attr("text")); // -> Thank
console.log(node.get("opml").get("body").get("outline",1).get("outline",0).attr("text")); // -> Thank you.
console.log(node.get("opml").get("body").get("outline",1).get("outline",1).attr("text")); // -> Appreciate it.
```