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.

247 lines
11 KiB

  1. <?xml version="1.0" standalone="no"?>
  2. <!--
  3. * Licensed to the Apache Software Foundation (ASF) under one or more
  4. * contributor license agreements. See the NOTICE file distributed with
  5. * this work for additional information regarding copyright ownership.
  6. * The ASF licenses this file to You under the Apache License, Version 2.0
  7. * (the "License"); you may not use this file except in compliance with
  8. * the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. -->
  18. <!DOCTYPE s1 SYSTEM "sbk:/style/dtd/document.dtd">
  19. <s1 title="XML Schema Support">
  20. <s2 title="Introduction">
  21. <p>&XercesCName; includes an implementation of the W3C XML Schema
  22. specification, a recommendation of the Worldwide Web Consortium
  23. available in three parts:
  24. <jump href="http://www.w3.org/TR/xmlschema-0/">XML Schema: Primer</jump>,
  25. <jump href="http://www.w3.org/TR/xmlschema-1/">XML Schema: Structures</jump> and
  26. <jump href="http://www.w3.org/TR/xmlschema-2/">XML Schema: Datatypes</jump>.
  27. We consider this implementation complete except for the limitations outlined below.
  28. </p>
  29. </s2>
  30. <anchor name="limitation"/>
  31. <s2 title="Limitations">
  32. <ul>
  33. <li>In certain complex content models specifying large
  34. values for the <code>minOccurs</code> or <code>maxOccurs</code>
  35. attributes may result in poor performance and/or large amount
  36. of memory being allocated by the parser. In such situations large values for
  37. <code>minOccurs</code> should be avoided, and <code>unbounded</code>
  38. should be used instead.</li>
  39. <li>The parser treats local elements in the same scope with the
  40. same name and namespace as one element declaration and does not
  41. differentiate between them.</li>
  42. </ul>
  43. </s2>
  44. <anchor name="interpretation"/>
  45. <s2 title="Interpretation of Areas that are Unclear or Implementation-Dependent">
  46. <s3 title="keyref">
  47. <p>
  48. We have interpreted the specs as requiring &lt;keyref&gt; Identity Constraints to refer to
  49. &lt;key&gt; or &lt;unique&gt; identity constraints within the scope of the elements to which
  50. the &lt;keyref&gt; is attached. This interpretation is at variance with the Schema Primer, which
  51. contains an example with a &lt;keyref&gt; declared on an element used inside the element of its
  52. corresponding &lt;key&gt;.
  53. </p>
  54. </s3>
  55. <s3 title="out-of-bound float values">
  56. <p>
  57. For float data, the specification does not explicitly prescribe how to deal with
  58. out-of-bound data. &XercesCName; converts these values as shown below:
  59. </p>
  60. <table>
  61. <tr>
  62. <td>Values in range</td>
  63. <td>Values converted</td>
  64. </tr>
  65. <tr>
  66. <td>less than -2<sup>24</sup> * 2<sup>104</sup> (approx -3.402823669e+38) </td>
  67. <td>-INF</td>
  68. </tr>
  69. <tr>
  70. <td>greater than -1 * 2<sup>-149</sup> (approx -1.401298464e-45) and less than -0 </td>
  71. <td>-0</td>
  72. </tr>
  73. <tr>
  74. <td>greater than +0 and less than +1 * 2<sup>-149</sup> (approx +1.401298464e-45) </td>
  75. <td>+0</td>
  76. </tr>
  77. <tr>
  78. <td>greater than +2<sup>24</sup> * 2<sup>104</sup> (approx 3.402823669e+38) </td>
  79. <td>+INF</td>
  80. </tr>
  81. </table>
  82. <p>
  83. The effect of this conversion would invalidate an instance data, for example,
  84. "1.1e-46", of a data type derived from float, with minExclusive value '+0',
  85. since "1.1e-46" is converted to "+0", which is the same as the minExclusive.
  86. </p>
  87. </s3>
  88. <s3 title="out-of-bound double values">
  89. <p>
  90. Similarly, &XercesCName; converts double values as shown below (the values
  91. depend on the system specific values of DBL_MAX and DBL_MIN):
  92. </p>
  93. <table>
  94. <tr>
  95. <td>Values in range</td>
  96. <td>Values converted</td>
  97. </tr>
  98. <tr>
  99. <td>less than -DBL_MAX (approx -1.7976931348623158e+308) </td>
  100. <td>-INF</td>
  101. </tr>
  102. <tr>
  103. <td>greater than -DBL_MIN (approx -2.2250738585072014e-308) and less than -0 </td>
  104. <td>-0</td>
  105. </tr>
  106. <tr>
  107. <td>greater than +0 and less than +DBL_MIN (approx +2.2250738585072014e-308) </td>
  108. <td>+0</td>
  109. </tr>
  110. <tr>
  111. <td>greater than +DBL_MAX (approx +1.7976931348623158e+308) </td>
  112. <td>+INF</td>
  113. </tr>
  114. </table>
  115. </s3>
  116. </s2>
  117. <anchor name="usage"/>
  118. <s2 title="Usage">
  119. <p>Below is an example that shows how to turn on schema processing in DOMParser
  120. (default is off). Note that you must also turn on namespace support
  121. (default is off) for schema processing.
  122. </p>
  123. <source>// Instantiate the DOM parser.
  124. XercesDOMParser parser;
  125. parser.setDoNamespaces(true);
  126. parser.setDoSchema(true);
  127. parser.parse(xmlFile);
  128. </source>
  129. <p>Usage in SAXParser is similar, please refer to the SAXCount
  130. sample program for further reference.
  131. </p>
  132. <p>Below is an example that shows how to turn on schema processing in SAX2XMLReader
  133. (default is on). Note that namespace must be on (default is on) as well.
  134. </p>
  135. <source>SAX2XMLReader* parser = XMLReaderFactory::createXMLReader();
  136. parser->setFeature(XMLUni::fgSAX2CoreNameSpaces, true);
  137. parser->setFeature(XMLUni::fgXercesSchema, true);
  138. parser->parse(xmlFile);
  139. </source>
  140. </s2>
  141. <anchor name="associate"/>
  142. <s2 title="Associating Schema Grammar with instance document">
  143. <p>Schema grammars can be associated with instance documents in three ways.
  144. </p>
  145. <s3 title="Specifying Schema Grammar through attributes in the instance document">
  146. <p>If schema grammar was not specified externally through methods,
  147. then each instance document that uses XML Schema grammars must specify the location of
  148. the grammars it uses by using an xsi:schemaLocation attribute if they use
  149. namespaces, and xsi:noNamespaceSchemaLocation attribute otherwise.
  150. </p>
  151. <p>Here is an example with no target namespace:
  152. </p>
  153. <source>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  154. &lt;personnel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  155. xsi:noNamespaceSchemaLocation='personal.xsd'&gt;
  156. ...
  157. &lt;/personnel&gt;
  158. </source>
  159. <p>Here is an example with a target namespace. Note that it is an error to specify a
  160. different namespace in xsi:schemaLocation attribute than the target namespace
  161. defined in the Schema.
  162. </p>
  163. <source>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  164. &lt;personnel xmlns="http://my.com"
  165. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  166. xsi:schemaLocation="http://my.com personal.xsd http://my2.com test2.xsd"&gt;
  167. ...
  168. &lt;/personnel&gt;
  169. </source>
  170. </s3>
  171. <s3 title="Specifying Schema Grammar through method calls">
  172. <p>An application developer may associate schemas with instance documents through
  173. methods <code>setExternalSchemaLocation</code> if they use namespaces, and
  174. <code>setExternalNoNamespaceSchemaLocation</code> otherwise.
  175. (For SAX2XMLReader, use the properties:
  176. "http://apache.org/xml/properties/schema/external-schemaLocation" and
  177. "http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation")
  178. </p>
  179. <p>Here is an example with no target namespace:
  180. </p>
  181. <source>
  182. // Instantiate the DOM parser.
  183. XercesDOMParser parser;
  184. parser.setDoNamespaces(true);
  185. parser.setDoSchema(true);
  186. parser.setExternalNoNamespaceSchemaLocation("personal.xsd");
  187. parser.parse("test.xml");
  188. // Instantiate the SAX2 XMLReader.
  189. SAX2XMLReader* parser = XMLReaderFactory::createXMLReader();
  190. XMLCh* propertyValue = XMLString::transcode("personal.xsd");
  191. ArrayJanitor&lt;XMLCh&gt; janValue(propertyValue);
  192. parser->setProperty(
  193. XMLUni::fgXercesSchemaExternalNoNameSpaceSchemaLocation,
  194. propertyValue);
  195. parser.parse("test.xml");
  196. </source>
  197. <p>Here is an example with a target namespace. Note that it is an error to specify a
  198. different namespace in <code>setExternalSchemaLocation</code> than the target
  199. namespace defined in the Schema.
  200. </p>
  201. <source>
  202. // Instantiate the DOM parser.
  203. XercesDOMParser parser;
  204. parser.setDoNamespaces(true);
  205. parser.setDoSchema(true);
  206. parser.setExternalSchemaLocation(
  207. "http://my.com personal.xsd http://my2.com test2.xsd");
  208. parser.parse("test.xml");
  209. // Instantiate the SAX2 XMLReader.
  210. SAX2XMLReader* parser = XMLReaderFactory::createXMLReader();
  211. XMLCh* propertyValue = XMLString::transcode(
  212. "http://my.com personal.xsd http://my2.com test2.xsd");
  213. ArrayJanitor&lt;XMLCh&gt; janValue(propertyValue);
  214. parser->setProperty(
  215. XMLUni::fgXercesSchemaExternalSchemaLocation,
  216. propertyValue);
  217. parser.parse("test.xml");
  218. </source>
  219. </s3>
  220. <s3 title="Pre-parsing and Caching Schema Grammar">
  221. <p>An application developer may also pre-parse and
  222. cache the grammar corresponding to the XML document
  223. namespace as described in the
  224. <jump href="program-others-&XercesC3Series;.html#GrammarCache">Pre-parsing
  225. Grammar and Grammar Caching</jump> section of the
  226. &XercesCName; Programming Guide.</p>
  227. </s3>
  228. </s2>
  229. </s1>