What is the xs: NCName type and when should it be used?

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

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

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

+78
xml xml-namespaces xsd
Oct 27 '09 at 2:58 p.m.
source share
4 answers

NCName is a non-colonized name, for example. "name". Compared to QName, which is a qualified name, for example. "Ns: name." If your names do not have to match other namespaces, then these are NCNames.

xs: string does not contain any restrictions on your names, but xs: NCName basically prevents ":" from appearing in a string.

+71
Oct 27 '09 at 15:11
source share

@skyl practically provoked me to write this answer, so please consider redundancy.

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

... and what does this regular expression mean?

\i and \c are multi-character escape sequences defined in the XML schema definition.
http://www.w3.org/TR/xmlschema-2/#dt-ccesN
\i is the escape for the source character set of the XML name, and \c is the character set of the XML name. [\i-[:]] means a set consisting of a set \i , except for a set consisting of a colon : Thus, in plain English, this would mean "any initial character, but not : ". The entire regular expression reads as "One starting character of the XML name, but not a colon, followed by zero or more characters of the XML name, but not a colon."

Practical limitations of NCName

The practical limitations of NCName are that it cannot contain multiple character characters, such as : @ , $ , % , & , / , + ,,, ; , whitespace or different brackets. In addition, NCName cannot begin with a number, period, or minus character, although they may appear later in NCName.

Where are NCNames needed?

In consistent XML namespace documents, names must be either qualified names or NCNames. The following values ​​should be NCNames (non-qualified names):

  • namespace prefixes
  • values ​​representing an identifier
  • values ​​representing idref
  • NOTATION values
  • Processing objectives
  • entity names
+92
May 28 '11 at 1:00
source share

Practically speaking ...

Allowed characters: - ,. , 0 , 1 , 2 , 3 , 4 , 5 , 6 , 8 , 8 , 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

In addition, - and . cannot be used as the first character of a value.

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

+20
Jun 05 '13 at 20:17
source share

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

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

You would use this instead of a string so that you can verify that the value is limited to valid. It displays well certain conventions for the name / identifier, for example, the django "slug" concept.

I am promoting a person who [\i-[:]][\c-[:]]* translates into English for us.

+4
May 26 '11 at 16:54
source share



All Articles