Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

xmlobject

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

xmlobject

Convert javascript objects to and from xml strings.

  • 0.6.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
558
increased by7.31%
Maintainers
1
Weekly downloads
 
Created
Source

xmlobject

Convert javascript object from and to xml string.

Install

$ npm install --save xmlobject

Quickstart

var XML = require('xmlobject');

// Deserialize from xml

var ns = "http://www.example.com/xml/test"
var defaultns = "http://www.example.com/xml/default"
var s = '<a xmlns="'+defaultns+'" xmlns:test="'+ns+'" b="c" d="e"><test:f test:i="j">g<h /></test:f></a>';

XML.deserialize(s, function(err,r) {
    console.log(r.asJSON())
    var f1 = r.firstChild(ns,"f");
    console.log("i: " + f1.getAttribute(ns, "i"));
    console.log("f: " + f1.getText());

    /* ->
    {"name":"a","attributes":{"xmlns:":"http://www.example.com/xml/default","xmlns":"http://www.example.com/xml/default","xmlns:test":"http://www.example.com/xml/test","b":"c","d":"e"},"namespaces":[{"prefix":"","value":"http://www.example.com/xml/default"},{"prefix":"test","value":"http://www.example.com/xml/test"}],"children":[{"name":"test:f","attributes":{"test:i":"j"},"namespaces":[],"children":["g",{"name":"h","attributes":{},"namespaces":[],"children":[]}]}]}
    */

});

// Serialize to xml

var a = new XML("a");
a.setAttribute("b","c");
a.setAttribute("d","e");
a.setNamespace(defaultns);
a.addNamespace("test", ns);

var f = a.createChild(ns,"f");
f.setAttribute(ns,"i","j");
f.addChild("g");
f.createChild("h");

a.serialize(function(err, r) {
    console.log(r);

     /* ->
    <a b="c" d="e" xmlns="http://www.example.com/xml/default" xmlns:test="http://www.example.com/xml/test"><test:f test:i="j">g<h /></test:f></a>
    */
});

Warning

xmlobject is a perfect fit for small parsing scenario where all data could remain in memory but would not be perfectly optimized for parsing mega-octets of xml content where a stream/sax based approach would be better.

MIT © Aloïs Deniel

Keywords

FAQs

Package last updated on 26 Apr 2017

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc