什么是xs:NCName类型,应该在什么时候使用?

时间:2021-07-19 18:06:26

I ran one of my xml files through a schema generator and everything generated was what was expected, with the exception of one node:

我通过模式生成器运行了一个xml文件,生成的所有内容都符合预期,只有一个节点例外:

<xs:element name="office" type="xs:NCName"/>

What exactly is xs:NCName? And why would one use it, rather xs:string?

究竟什么是xs:NCName吗?为什么要用它,而不是xs:string?

4 个解决方案

#1


77  

NCName is non-colonized name e.g. "name". Compared to QName which is qualified name e.g. "ns:name". If your names are not supposed to be qualified by different namespaces, then they are NCNames.

NCName是非定殖名称,例如。“名字”。与QName比较,QName是限定名。“ns:名称”。如果您的名称不应该被不同的名称空间限定,那么它们就是ncname。

xs:string puts no restrictions on your names at all, but xs:NCName basically disallows ":" to appear in the string.

字符串对您的名字没有任何限制,但是xs:NCName基本上不允许出现在字符串中。

#2


98  

@skyl practically provoked me to write this answer so please mind the redundancy.

@skyl实际上激发了我写下这个答案,所以请注意冗余。

NCName stands for "non-colonized name". NCName can be defined as an XML Schema regular expression [\i-[:]][\c-[:]]*

NCName代表“非殖民化名称”。NCName可以定义为一个XML模式正则表达式[\i-[:]][\c-[:]]*

...and what does that regex mean?

\i and \c are multi-character escapes defined in XML Schema definition.
http://www.w3.org/TR/xmlschema-2/#dt-ccesN
\i is the escape for the set of initial XML name characters and \c is the set of XML name characters. [\i-[:]] means a set that consist of the set \i excluding a set that consist of the colon character :. So in plain English it would mean "any initial character, but not :". The whole regular expression reads as "One initial XML name character, but not a colon, followed by zero or more XML name characters, but not a colon."

\i和\c是XML模式定义中定义的多字符转义。我是一组初始XML名字符的转义,而\c是XML名字符的集合。[\i-[:]]指由set \i组成的集合,不包括由冒号字符构成的集合:。因此,在简单的英语中,它意味着“任何初始字符,但不是:”。整个正则表达式读取为“一个初始的XML名称字符,但不是冒号,后面是零或多个XML名称字符,但不是冒号。”

Practical restrictions of an NCName

The practical restrictions of NCName are that it cannot contain several symbol characters like :, @, $, %, &, /, +, ,, ;, whitespace characters or different parenthesis. Furthermore an NCName cannot begin with a number, dot or minus character although they can appear later in an NCName.

NCName的实际限制是,它不能包含以下几个符号字符:,@,$,%,&,/,+,;,空格字符或不同的括号。此外,NCName不能以数字、点或减号开头,尽管它们稍后会出现在NCName中。

Where are NCNames needed

In namespace conformant XML documents all names must be either qualified names or NCNames. The following values must be NCNames (not qualified names):

在命名空间一致性XML文档中,所有名称必须是限定名或ncname。下列值必须是NCNames(非限定名):

  • namespace prefixes
  • 名称空间前缀
  • values representing an ID
  • 值代表一个ID
  • values representing an IDREF
  • 代表一个IDREF值
  • values representing a NOTATION
  • 值代表一个符号
  • processing instruction targets
  • 处理指令的目标
  • entity names
  • 实体名称

#3


21  

Practically speaking...

实际上……

Allowed characters: -, ., 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z, _, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z

允许字符:,,0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,_,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z

Also, - and . cannot be used as the first character of the value.

同时,,。不能用作值的第一个字符。

Disallowed characters: , !, ", #, $, %, &, ', (, ), *, +, ,, /, :, ;, <, =, >, ?, @, [, \, ], ^, `, {, |, }, ~

无效字符:!”,# $,%,&,”(,),*,+,,,和,,,,,< =,>,?,@,[,\],^,",{ |,},~

#4


4  

http://books.xmlschemata.org/relaxng/ch19-77215.html

http://books.xmlschemata.org/relaxng/ch19 - 77215. - html

No spaces or colons. Allows "_" and "-".

没有空格或冒号。允许“_”、“-”。

You would use this instead of string so that you can validate that the value is limited to what is allowed. It maps well to certain conventions for name/identifier like django's concept of "slug", for instance.

您将使用这个而不是字符串,以便您可以验证该值是否受允许的内容的限制。它很好地映射到名称/标识符的某些约定,例如django的“slug”概念。

I upvote the person who [\i-[:]][\c-[:]]* translates into English for us.

我投票给[\ I -]][\c-[:]]*为我们翻译成英语的人。

#1


77  

NCName is non-colonized name e.g. "name". Compared to QName which is qualified name e.g. "ns:name". If your names are not supposed to be qualified by different namespaces, then they are NCNames.

NCName是非定殖名称,例如。“名字”。与QName比较,QName是限定名。“ns:名称”。如果您的名称不应该被不同的名称空间限定,那么它们就是ncname。

xs:string puts no restrictions on your names at all, but xs:NCName basically disallows ":" to appear in the string.

字符串对您的名字没有任何限制,但是xs:NCName基本上不允许出现在字符串中。

#2


98  

@skyl practically provoked me to write this answer so please mind the redundancy.

@skyl实际上激发了我写下这个答案,所以请注意冗余。

NCName stands for "non-colonized name". NCName can be defined as an XML Schema regular expression [\i-[:]][\c-[:]]*

NCName代表“非殖民化名称”。NCName可以定义为一个XML模式正则表达式[\i-[:]][\c-[:]]*

...and what does that regex mean?

\i and \c are multi-character escapes defined in XML Schema definition.
http://www.w3.org/TR/xmlschema-2/#dt-ccesN
\i is the escape for the set of initial XML name characters and \c is the set of XML name characters. [\i-[:]] means a set that consist of the set \i excluding a set that consist of the colon character :. So in plain English it would mean "any initial character, but not :". The whole regular expression reads as "One initial XML name character, but not a colon, followed by zero or more XML name characters, but not a colon."

\i和\c是XML模式定义中定义的多字符转义。我是一组初始XML名字符的转义,而\c是XML名字符的集合。[\i-[:]]指由set \i组成的集合,不包括由冒号字符构成的集合:。因此,在简单的英语中,它意味着“任何初始字符,但不是:”。整个正则表达式读取为“一个初始的XML名称字符,但不是冒号,后面是零或多个XML名称字符,但不是冒号。”

Practical restrictions of an NCName

The practical restrictions of NCName are that it cannot contain several symbol characters like :, @, $, %, &, /, +, ,, ;, whitespace characters or different parenthesis. Furthermore an NCName cannot begin with a number, dot or minus character although they can appear later in an NCName.

NCName的实际限制是,它不能包含以下几个符号字符:,@,$,%,&,/,+,;,空格字符或不同的括号。此外,NCName不能以数字、点或减号开头,尽管它们稍后会出现在NCName中。

Where are NCNames needed

In namespace conformant XML documents all names must be either qualified names or NCNames. The following values must be NCNames (not qualified names):

在命名空间一致性XML文档中,所有名称必须是限定名或ncname。下列值必须是NCNames(非限定名):

  • namespace prefixes
  • 名称空间前缀
  • values representing an ID
  • 值代表一个ID
  • values representing an IDREF
  • 代表一个IDREF值
  • values representing a NOTATION
  • 值代表一个符号
  • processing instruction targets
  • 处理指令的目标
  • entity names
  • 实体名称

#3


21  

Practically speaking...

实际上……

Allowed characters: -, ., 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z, _, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z

允许字符:,,0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,_,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z

Also, - and . cannot be used as the first character of the value.

同时,,。不能用作值的第一个字符。

Disallowed characters: , !, ", #, $, %, &, ', (, ), *, +, ,, /, :, ;, <, =, >, ?, @, [, \, ], ^, `, {, |, }, ~

无效字符:!”,# $,%,&,”(,),*,+,,,和,,,,,< =,>,?,@,[,\],^,",{ |,},~

#4


4  

http://books.xmlschemata.org/relaxng/ch19-77215.html

http://books.xmlschemata.org/relaxng/ch19 - 77215. - html

No spaces or colons. Allows "_" and "-".

没有空格或冒号。允许“_”、“-”。

You would use this instead of string so that you can validate that the value is limited to what is allowed. It maps well to certain conventions for name/identifier like django's concept of "slug", for instance.

您将使用这个而不是字符串,以便您可以验证该值是否受允许的内容的限制。它很好地映射到名称/标识符的某些约定,例如django的“slug”概念。

I upvote the person who [\i-[:]][\c-[:]]* translates into English for us.

我投票给[\ I -]][\c-[:]]*为我们翻译成英语的人。