|
Last change
on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago |
|
Fix frontend appearance
|
-
Property mode
set to
100644
|
|
File size:
1.2 KB
|
| Line | |
|---|
| 1 | # Validate XML Names and Qualified Names
|
|---|
| 2 |
|
|---|
| 3 | This package simply tells you whether or not a string matches the [`Name`](http://www.w3.org/TR/xml/#NT-Name) or [`QName`](http://www.w3.org/TR/xml-names/#NT-QName) productions in the XML Namespaces specification. We use it for implementing the [validate](https://dom.spec.whatwg.org/#validate) algorithm in jsdom, but you can use it for whatever you want.
|
|---|
| 4 |
|
|---|
| 5 | ## Usage
|
|---|
| 6 |
|
|---|
| 7 | This package's main module's default export takes a string and will return an object of the form `{ success, error }`, where `success` is a boolean and if it is `false`, then `error` is a string containing some hint as to where the match went wrong.
|
|---|
| 8 |
|
|---|
| 9 | ```js
|
|---|
| 10 | "use strict":
|
|---|
| 11 | var xnv = require("xml-name-validator");
|
|---|
| 12 | var assert = require("assert");
|
|---|
| 13 |
|
|---|
| 14 | // Will return { success: true, error: undefined }
|
|---|
| 15 | xnv.name("x");
|
|---|
| 16 | xnv.name(":");
|
|---|
| 17 | xnv.name("a:0");
|
|---|
| 18 | xnv.name("a:b:c");
|
|---|
| 19 |
|
|---|
| 20 | // Will return { success: false, error: <an explanatory string> }
|
|---|
| 21 | xnv.name("\\");
|
|---|
| 22 | xnv.name("'");
|
|---|
| 23 | xnv.name("0");
|
|---|
| 24 | xnv.name("a!");
|
|---|
| 25 |
|
|---|
| 26 | // Will return { success: true, error: undefined }
|
|---|
| 27 | xnv.qname("x");
|
|---|
| 28 | xnv.qname("a0");
|
|---|
| 29 | xnv.qname("a:b");
|
|---|
| 30 |
|
|---|
| 31 | // Will return { success: false, error: <an explanatory string> }
|
|---|
| 32 | xnv.qname(":a");
|
|---|
| 33 | xnv.qname(":b");
|
|---|
| 34 | xnv.qname("a:b:c");
|
|---|
| 35 | xnv.qname("a:0");
|
|---|
| 36 | ```
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.