elementFormDefault取值:qualified 或者 unqualified
在http://www.velocityreviews.com/forums/t292290-xsd-what-is-elementformdefault-qualified-for.html這個網(wǎng)站,發(fā)現(xiàn)Boris的回答:
All"qualified" elements and attributes are in the targetNamespace of the
schema and all "unqualified" elementsand attributes are in no namespace.
All global elements and attributes are qualified.
意思是這樣的:
1、在xml中,所有引用xsd的全局的元素都必須加上命名空間的前綴
(例如xmlns:aa=http://www.example.org/classroom,全局元素都得加上aa)。
2、非全局的元素當(dāng)設(shè)置為qualified時,必須添加命名空間的前綴。
3、非全局的元素當(dāng)設(shè)置為unqualified時,不必也不能添加前綴。
下面是一個簡單的例子:
a. 當(dāng)設(shè)置為unqualified時,user為全局元素(可作為根元素)必須添加前綴,非全局元素
(id,name)不必添加前綴。


b. 當(dāng)設(shè)置為qualified時,所有的元素都必須添加前綴。
其實elementFormDefault的qualified/unqualified還與schema的設(shè)計模式有關(guān)系,目前常用的有Russian Roll , Salami Slice , Venetian Blind
詳細及最佳實踐可以參照:http://www.xfront.com/GlobalVersusLocal.html#BestPractice
Salami Slice這種schema的設(shè)計模式,將所有的元素設(shè)置為全局元素,設(shè)置不設(shè)置elementFormDefault是沒有任何意義的,文章的開通說過,所有的全局元素必須添加前綴。
http://www.xfront.com/GlobalVersusLocal.html#BestPractice
上網(wǎng)站中提到的Venetian Blind的優(yōu)勢之一:
UseelementFormDefault to act as a switch for controlling namespaceexposure - if you want element namespaces exposed in instance documents, simplyturn the elementFormDefault switch to "on" (i.e, setelementFormDefault= "qualified"); if you don't want elementnamespaces exposed in instance documents, simply turn the elementFormDefaultswitch to "off" (i.e., setelementFormDefault="unqualified").