版博士V2.0程序
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.

пре 1 година
1234567891011121314151617181920212223242526272829303132333435
  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 exports two functions, `name()` and `qname()`. Both take a string and return a boolean indicating whether or not the string matches the relevant production.
  5. ```js
  6. "use strict":
  7. const xnv = require("xml-name-validator");
  8. // Will return true
  9. xnv.name("x");
  10. xnv.name(":");
  11. xnv.name("a:0");
  12. xnv.name("a:b:c");
  13. // Will return false
  14. xnv.name("\\");
  15. xnv.name("'");
  16. xnv.name("0");
  17. xnv.name("a!");
  18. // Will return true
  19. xnv.qname("x");
  20. xnv.qname("a0");
  21. xnv.qname("a:b");
  22. // Will return false
  23. xnv.qname(":a");
  24. xnv.qname(":b");
  25. xnv.qname("a:b:c");
  26. xnv.qname("a:0");
  27. ```