An open API service indexing awesome lists of open source software.

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

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.

```