Socket
Socket
Sign inDemoInstall

libxmljs2

Package Overview
Dependencies
Maintainers
1
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

libxmljs2

libxml bindings for v8 javascript engine


Version published
Weekly downloads
137K
decreased by-0.27%
Maintainers
1
Weekly downloads
 
Created

What is libxmljs2?

libxmljs2 is a Node.js library that provides a fast and efficient way to parse, manipulate, and validate XML documents. It is a binding for the libxml2 library, which is a powerful XML parsing library written in C.

What are libxmljs2's main functionalities?

Parsing XML

This feature allows you to parse an XML string into a document object model (DOM) that you can manipulate programmatically. The code sample demonstrates how to parse a simple XML string and access the root element's name.

const libxmljs = require('libxmljs2');
const xml = '<root><child foo="bar">Content</child></root>';
const xmlDoc = libxmljs.parseXml(xml);
console.log(xmlDoc.root().name()); // 'root'

XPath Queries

This feature allows you to perform XPath queries on the parsed XML document. The code sample demonstrates how to query for a specific element using an XPath expression and retrieve its text content.

const libxmljs = require('libxmljs2');
const xml = '<root><child foo="bar">Content</child></root>';
const xmlDoc = libxmljs.parseXml(xml);
const result = xmlDoc.get('//child');
console.log(result.text()); // 'Content'

XML Validation

This feature allows you to validate an XML document against an XML Schema Definition (XSD). The code sample demonstrates how to parse an XSD and an XML document, and then validate the XML document against the XSD.

const libxmljs = require('libxmljs2');
const xsd = '<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"><xs:element name="root"/></xs:schema>';
const xml = '<root></root>';
const xsdDoc = libxmljs.parseXml(xsd);
const xmlDoc = libxmljs.parseXml(xml);
const isValid = xmlDoc.validate(xsdDoc);
console.log(isValid); // true

Other packages similar to libxmljs2

FAQs

Package last updated on 04 Nov 2023

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