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

xml-extract

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

xml-extract

Extract elements from XML

latest
Source
npmnpm
Version
1.1.0
Version published
Maintainers
1
Created
Source

xml-extract

Node module for extracting elements from XML

Installtion

npm install xml-extract

Usage

const XML = `
<urlset xmlns="http://www.example.com">
  <url>
    <loc>http://www.example.com/1</loc>
  </url>
  <url>
    <loc>http://www.example.com/2</loc>
  </url>
  <url>
    <loc>http://www.example.com/3</loc>
  </url>
<urlset>`

const XMLExtract = require('xml-extract');

// Extract <loc> without tags
XMLExtract(XML, 'loc', false, (error, element) => {
  if (error) {
    throw new Error(error);
  }

  console.log(element);

  // output: 
  // http://www.example.com/1
  // http://www.example.com/2
  // http://www.example.com/3
});

// Extract <loc> with tags
XMLExtract(XML, 'loc', true, (error, element) => {
  if (error) {
    throw new Error(error);
  }

  console.log(element);

  // output: 
  // <loc>http://www.example.com/1</loc>
  // <loc>http://www.example.com/2</loc>
  // <loc>http://www.example.com/3</loc>
});

Test

npm run test

Keywords

xml parse

FAQs

Package last updated on 29 Mar 2016

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