
Research
Security News
The Growing Risk of Malicious Browser Extensions
Socket researchers uncover how browser extensions in trusted stores are used to hijack sessions, redirect traffic, and manipulate user behavior.
jsxml is an XML library for javascript (and node)
npm install node-jsxml
After add this library to your project, there will be a global object named jsxml.
in HTML file, import using <script> elements.
<script src="jsxml.js"></script>
in Node, import using require
function.
const jsxml = require("node-jsxml");
support AMD, CMD. Big thanks to TimSchlechter.
seajs.config({
alias: {
jsxml: '../src/jsxml.js'
}
});
seajs.use('jsxml', function(jsxml){
console.log(jsxml);
});
var Namespace = jsxml.Namespace,
QName = jsxml.QName,
XML = jsxml.XML,
XMLList = jsxml.XMLList;
Here you go:
var xml = new XML("<spring>" +
"<list id='data'>" +
"<element value='jsxml'/>" +
"<element value='is'/>" +
"<element value='an'/>" +
"<element value='xml'/>" +
"<element value='parser'/>" +
"</list>" +
"</spring>");
find special childs
var child = xml.child('list');
find all children by *
var children = xml.child('*');
print the xml string
console.log(xml.toXMLString());
modify namespace
xml.addNamespace(new Namespace("ns", "http://colorhook.com"));
xml.children().addNamespace(new Namespace("prefix", "uri"));
console.log(xml.toXMLString());
find descendants nodes
var descendants = xml.descendants('element');
get all children
var children = xml.children();
//or
var children = xml.child('*');
get text node
var text = xml.text();
get element node
var elements = xml.elements();
get comment node
var comments = xml.comments();
get attribute
var attribute = xml.attribute("id");
get all attributes
var attributes = xml.attributes();
All methods above return an XML object or XMLList object, if you want to get the String type content, you should:
var xml = new XML(xmlContent);
var attrValue = xml.attribute('attrName').toString();
//or
var attrValue = xml.attribute('attrName').getValue();
var childA = xml.child('a').toString();
//or
var childA = xml.child('a').getValue();
If you want to modify the value, you should call method setValue:
var xml = new XML("your xml string");
var attr= xml.attribute('attrName');
attr.setValue("newValue");
var childA = xml.child('a');
childA.setValue("newValue");
You can regenerate the XML Content
var str = xml.toXMLString();
While dealing with a list of childs in XML tree, you should use XMLList API:
var list = xml.child("item");
list.each(function(item, index){
//item is an XML
});
You can also add, retrieve or remove namespaces:
var xml = new XML("your xml string");
var ns = xml.namespace("prefix");
var nsNew = new Namespace("prefix", 'uri');
xml.addNamespace(nsNew);
xml.removeNamespace(nsNew);
Please feel free report bugs or feature requests. You can send me private message on [github], or send me an email to: [colorhook@gmail.com]
jsxml is free to use under MIT license.
FAQs
an XML parser for javascript and node.js
The npm package node-jsxml receives a total of 284 weekly downloads. As such, node-jsxml popularity was classified as not popular.
We found that node-jsxml demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Research
Security News
Socket researchers uncover how browser extensions in trusted stores are used to hijack sessions, redirect traffic, and manipulate user behavior.
Research
Security News
An in-depth analysis of credential stealers, crypto drainers, cryptojackers, and clipboard hijackers abusing open source package registries to compromise Web3 development environments.
Security News
pnpm 10.12.1 introduces a global virtual store for faster installs and new options for managing dependencies with version catalogs.