Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
815 views
in Technique[技术] by (71.8m points)

xml - What is an xs:NCName type and when should it be used?

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

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

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

NCName stands for "non-colonized name". NCName can be defined as an XML Schema regular expression [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."

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.

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):

  • namespace prefixes
  • values representing an ID
  • values representing an IDREF
  • values representing a NOTATION
  • processing instruction targets
  • entity names

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...