You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
1.2 KiB

  1. # Validate XML Names and Qualified Names
  2. 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.
  3. ## Usage
  4. 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.
  5. ```js
  6. "use strict":
  7. var xnv = require("xml-name-validator");
  8. var assert = require("assert");
  9. // Will return { success: true, error: undefined }
  10. xnv.name("x");
  11. xnv.name(":");
  12. xnv.name("a:0");
  13. xnv.name("a:b:c");
  14. // Will return { success: false, error: <an explanatory string> }
  15. xnv.name("\\");
  16. xnv.name("'");
  17. xnv.name("0");
  18. xnv.name("a!");
  19. // Will return { success: true, error: undefined }
  20. xnv.qname("x");
  21. xnv.qname("a0");
  22. xnv.qname("a:b");
  23. // Will return { success: false, error: <an explanatory string> }
  24. xnv.qname(":a");
  25. xnv.qname(":b");
  26. xnv.qname("a:b:c");
  27. xnv.qname("a:0");
  28. ```