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

mergexml

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mergexml

Merge multiple XML sources

  • 1.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
69K
decreased by-20.72%
Maintainers
1
Weekly downloads
 
Created
Source

JS MergeXML class

The class allows to merge the XML sources (files, strings, objects) into single DOM XML object. The merging is performed recursively on the node level adding new elements and replacing existing ones. The nodes with the same path/name are replaced/added sequentially and the modification can be controlled by the options.

MergeXML could be useful in cases where it is necessary to gather XML data from multiple sources. For example, to join the configuration files of different subsystems depending on the system operation.

The usage

var oMX = new MergeXML([opts]);

opts - the options object:

  • join - common root name if any source has different root name (default is root, specifying false denies different names)
  • updn - traverse the nodes by name sequence (true, default) or overall sequence (false)
  • stay - the stay attribute value to deny overwriting of specific node (default is all, can be array of values or empty)

oMX.AddFile(elem);

elem - FileList element of the XML file

oMX.AddSource(source);

source - XML string or DOM object

The methods merge a sequent source and return the final object or false if failed (see error property below).

You can search in the result object:

oMX.Query(expr);

expr - XPath query expression

You can get the XML result tree:

oMX.Get([0|1|2]);

  • 0 - object (default)
  • 1 - text
  • 2 - html

The result object can be accessed also via oMX.dom property. The properties available:

  • dom - result XML DOM object
  • nsp - namespaces object (prefix:URI)
  • count - number of sources merged
  • error - error information
  • error.code ('' is ok)
  • error.text

The sources must have the same default namespace (if have at all). Prefix '_' is reserved to handle default namespace. IE doesn't allow replacement of the root node attributes.

The package

The following files are included:

  1. mergexml.js - the MergeXML class; supports IE, Firefox, Safari, Chrome, Opera;
  2. example.html - multi-selects the xml files and displays result;
  3. example.js - passes the xml data and returns result; requires HTML5;
  4. test1.xml, test2.xml - test data for the example.

The MergeXML is realized also in PHP (see github.com).

ChangeLog

09 June 2015

  • mergexml.js
  • the wrapper is added for a compatibility with the AMD/CommonJS (Martijn van de Rijdt)

Keywords

FAQs

Package last updated on 10 Jun 2015

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