New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

xml2node

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

xml2node

Simple and easy XML parser

Source
npmnpm
Version
1.0.0
Version published
Weekly downloads
5
Maintainers
1
Weekly downloads
 
Created
Source

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.

Quick start

demo on the web

https://riversun.github.io/xml2node/

demo on node.js

clone this project and type

git clone https://github.com/riversun/xml2node.git
npm start

install via npm

npm install xml2node

How to use?

Access element of XML values/attributes like as follows.

Example input-XML

<?xml version="1.0" encoding="utf-8"?>
<opml version="2.0">
  <head>
    <title>Original Title</title>
    <flavor>RSS Example App</flavor>
    <source>https://example.com</source>
  </head>
  <body>
    <outline text="Greeting">
      <outline text="We say good morning in the morning."/>
      <outline text="We say hello at noon."/>
      <outline text="We say good evening at night."/>
    </outline>
    <outline text="Thank">
      <outline text="Thank you."/>
      <outline text="Appreciate it."/>
    </outline>
  </body>
</opml>

You can access XML values/attributes like this.

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("head").get("flavor").value()); // ->RSS Example App
console.log(node.get("opml").get("head").get("source").value()); // ->https://example.com
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.

FAQs

Package last updated on 11 Jul 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts