Socket
Socket
Sign inDemoInstall

xml-name-validator

Package Overview
Dependencies
0
Maintainers
6
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    xml-name-validator

Validates whether a string matches the production for an XML name or qualified name


Version published
Weekly downloads
21M
increased by3.13%
Maintainers
6
Install size
13.3 kB
Created
Weekly downloads
 

Package description

What is xml-name-validator?

The xml-name-validator npm package is used to check if a string is a valid XML name, according to the XML specification. It can validate both XML names and qualified names (QNames), which are used in XML documents to ensure that element and attribute names are compliant with the XML naming rules.

What are xml-name-validator's main functionalities?

Validating XML names

This feature allows you to validate whether a given string is a valid XML name. The `isName` function returns `true` if the string is a valid XML name, and `false` otherwise.

const { isName, isQName } = require('xml-name-validator');

const validName = 'validElement';
const invalidName = '1InvalidElement';

console.log(isName(validName)); // true
console.log(isName(invalidName)); // false

Validating XML qualified names (QNames)

This feature allows you to validate whether a given string is a valid XML qualified name (QName). The `isQName` function returns `true` if the string is a valid QName, which includes a namespace prefix, and `false` otherwise.

const { isName, isQName } = require('xml-name-validator');

const validQName = 'ns:validElement';
const invalidQName = 'ns:1InvalidElement';

console.log(isQName(validQName)); // true
console.log(isQName(invalidQName)); // false

Other packages similar to xml-name-validator

Readme

Source

Validate XML Names and Qualified Names

This package simply tells you whether or not a string matches the Name or QName productions in the XML Namespaces specification. We use it for implementing the validate algorithm in jsdom, but you can use it for whatever you want.

Usage

This package's main module exports two functions, name() and qname(). Both take a string and return a boolean indicating whether or not the string matches the relevant production.

"use strict":
const xnv = require("xml-name-validator");

// Will return true
xnv.name("x");
xnv.name(":");
xnv.name("a:0");
xnv.name("a:b:c");

// Will return false
xnv.name("\\");
xnv.name("'");
xnv.name("0");
xnv.name("a!");

// Will return true
xnv.qname("x");
xnv.qname("a0");
xnv.qname("a:b");

// Will return false
xnv.qname(":a");
xnv.qname(":b");
xnv.qname("a:b:c");
xnv.qname("a:0");

Keywords

FAQs

Last updated on 12 Nov 2023

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc