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.

721 lines
29 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="Programming Guide">
  20. <anchor name="Macro"/>
  21. <s2 title="Version Macro">
  22. <p>&XercesCName; defines a numeric preprocessor macro, _XERCES_VERSION, for users to
  23. introduce into their code to perform conditional compilation where the
  24. version of &XercesCName; is detected in order to enable or disable version
  25. specific capabilities. For example,
  26. </p>
  27. <source>
  28. #if _XERCES_VERSION >= 30102
  29. // Code specific to Xerces-C++ version 3.1.2 and later.
  30. #else
  31. // Old code.
  32. #endif
  33. </source>
  34. <p>The minor and revision (patch level) numbers have two digits of resolution
  35. which means that '1' becomes '01' and '2' becomes '02' in this example.
  36. </p>
  37. <p>There are also other string macros or constants to represent the Xerces-C++ version.
  38. Please refer to the <code>xercesc/util/XercesVersion.hpp</code> header for details.
  39. </p>
  40. </s2>
  41. <anchor name="Schema"/>
  42. <s2 title="Schema Support">
  43. <p>&XercesCName; contains an implementation of the W3C XML Schema
  44. Language. See the <jump href="schema-&XercesC3Series;.html">XML Schema Support</jump> page for details.
  45. </p>
  46. </s2>
  47. <anchor name="Progressive"/>
  48. <s2 title="Progressive Parsing">
  49. <p>In addition to using the <code>parse()</code> method to parse an XML File.
  50. You can use the other two parsing methods, <code>parseFirst()</code> and <code>parseNext()</code>
  51. to do the so called progressive parsing. This way you don't
  52. have to depend on throwing an exception to terminate the
  53. parsing operation.
  54. </p>
  55. <p>
  56. Calling <code>parseFirst()</code> will cause the DTD (both internal and
  57. external subsets), and any pre-content, i.e. everything up to
  58. but not including the root element, to be parsed. Subsequent calls to
  59. <code>parseNext()</code> will cause one more pieces of markup to be parsed,
  60. and propagated from the core scanning code to the parser (and
  61. hence either on to you if using SAX/SAX2 or into the DOM tree if
  62. using DOM).
  63. </p>
  64. <p>
  65. You can quit the parse any time by just not
  66. calling <code>parseNext()</code> anymore and breaking out of the loop. When
  67. you call <code>parseNext()</code> and the end of the root element is the
  68. next piece of markup, the parser will continue on to the end
  69. of the file and return false, to let you know that the parse
  70. is done. So a typical progressive parse loop will look like
  71. this:</p>
  72. <source>// Create a progressive scan token
  73. XMLPScanToken token;
  74. if (!parser.parseFirst(xmlFile, token))
  75. {
  76. cerr &lt;&lt; "scanFirst() failed\n" &lt;&lt; endl;
  77. return 1;
  78. }
  79. //
  80. // We started ok, so lets call scanNext()
  81. // until we find what we want or hit the end.
  82. //
  83. bool gotMore = true;
  84. while (gotMore &amp;&amp; !handler.getDone())
  85. gotMore = parser.parseNext(token);</source>
  86. <p>In this case, our event handler object (named 'handler')
  87. is watching for some criteria and will
  88. return a status from its <code>getDone()</code> method. Since
  89. the handler
  90. sees the SAX events coming out of the SAXParser, it can tell
  91. when it finds what it wants. So we loop until we get no more
  92. data or our handler indicates that it saw what it wanted to
  93. see.</p>
  94. <p>When doing non-progressive parses, the parser can easily
  95. know when the parse is complete and insure that any used
  96. resources are cleaned up. Even in the case of a fatal parsing
  97. error, it can clean up all per-parse resources. However, when
  98. progressive parsing is done, the client code doing the parse
  99. loop might choose to stop the parse before the end of the
  100. primary file is reached. In such cases, the parser will not
  101. know that the parse has ended, so any resources will not be
  102. reclaimed until the parser is destroyed or another parse is started.</p>
  103. <p>This might not seem like such a bad thing; however, in this case,
  104. the files and sockets which were opened in order to parse the
  105. referenced XML entities will remain open. This could cause
  106. serious problems. Therefore, you should destroy the parser instance
  107. in such cases, or restart another parse immediately. In a future
  108. release, a reset method will be provided to do this more cleanly.</p>
  109. <p>Also note that you must create a scan token and pass it
  110. back in on each call. This insures that things don't get done
  111. out of sequence. When you call <code>parseFirst()</code> or
  112. <code>parse()</code>, any
  113. previous scan tokens are invalidated and will cause an error
  114. if used again. This prevents incorrect mixed use of the two
  115. different parsing schemes or incorrect calls to
  116. <code>parseNext()</code>.</p>
  117. </s2>
  118. <anchor name="GrammarCache"/>
  119. <s2 title="Pre-parsing Grammar and Grammar Caching">
  120. <p>&XercesCName; provides a function to pre-parse the grammar so that users
  121. can check for any syntax error before using the grammar. Users can also optionally
  122. cache these pre-parsed grammars for later use during actual parsing.
  123. </p>
  124. <p>Here is an example:</p>
  125. <source>
  126. XercesDOMParser parser;
  127. // Enable schema processing.
  128. parser.setDoSchema(true);
  129. parser.setDONamespaces(true);
  130. // Let's preparse the schema grammar (.xsd) and cache it.
  131. Grammar* grammar = parser.loadGrammar(xmlFile, Grammar::SchemaGrammarType, true);
  132. </source>
  133. <p>Besides caching pre-parsed schema grammars, users can also cache any
  134. grammars encountered during an xml document parse.
  135. </p>
  136. <p>Here is an example:</p>
  137. <source>
  138. SAXParser parser;
  139. // Enable grammar caching by setting cacheGrammarFromParse to true.
  140. // The parser will cache any encountered grammars if it does not
  141. // exist in the pool.
  142. // If the grammar is DTD, no internal subset is allowed.
  143. parser.cacheGrammarFromParse(true);
  144. // Let's parse our xml file (DTD grammar)
  145. parser.parse(xmlFile);
  146. // We can get the grammar where the root element was declared
  147. // by calling the parser's method getRootGrammar;
  148. // Note: The parser owns the grammar, and the user should not delete it.
  149. Grammar* grammar = parser.getRootGrammar();
  150. </source>
  151. <p>We can use any previously cached grammars when parsing new xml
  152. documents. Here are some examples on how to use those cached grammars:
  153. </p>
  154. <source>
  155. /**
  156. * Caching and reusing XML Schema (.xsd) grammar
  157. * Parse an XML document and cache its grammar set. Then, use the cached
  158. * grammar set in subsequent parses.
  159. */
  160. XercesDOMParser parser;
  161. // Enable schema processing
  162. parser.setDoSchema(true);
  163. parser.setDoNamespaces(true);
  164. // Enable grammar caching
  165. parser.cacheGrammarFromParse(true);
  166. // Let's parse the XML document. The parser will cache any grammars encountered.
  167. parser.parse(xmlFile);
  168. // No need to enable re-use by setting useCachedGrammarInParse to true. It is
  169. // automatically enabled with grammar caching.
  170. for (int i=0; i&lt; 3; i++)
  171. parser.parse(xmlFile);
  172. // This will flush the grammar pool
  173. parser.resetCachedGrammarPool();
  174. </source>
  175. <source>
  176. /**
  177. * Caching and reusing DTD grammar
  178. * Preparse a grammar and cache it in the pool. Then, we use the cached grammar
  179. * when parsing XML documents.
  180. */
  181. SAX2XMLReader* parser = XMLReaderFactory::createXMLReader();
  182. // Load grammar and cache it
  183. parser->loadGrammar(dtdFile, Grammar::DTDGrammarType, true);
  184. // enable grammar reuse
  185. parser->setFeature(XMLUni::fgXercesUseCachedGrammarInParse, true);
  186. // Parse xml files
  187. parser->parse(xmlFile1);
  188. parser->parse(xmlFile2);
  189. </source>
  190. <p>There are some limitations about caching and using cached grammars:</p>
  191. <ul>
  192. <li>When caching/reusing DTD grammars, no internal subset is allowed.</li>
  193. <li>When preparsing grammars with caching option enabled, if a grammar, in the
  194. result set, already exists in the pool (same namespace for schema or same system
  195. id for DTD), the entire set will not be cached. This behavior is the default but can
  196. be overridden for XML Schema caching. See the SAX/SAX2/DOM parser features for details.</li>
  197. <li>When parsing an XML document with the grammar caching option enabled, the
  198. reuse option is also automatically enabled. We will only parse a grammar if it
  199. does not exist in the pool.</li>
  200. </ul>
  201. </s2>
  202. <anchor name="LoadableMessageText"/>
  203. <s2 title="Loadable Message Text">
  204. <p>The &XercesCName; supports loadable message text. Although
  205. the current distribution only supports English, it is capable of
  206. supporting other
  207. languages. Anyone interested in contributing any translations
  208. should contact us. This would be an extremely useful
  209. service.</p>
  210. <p>In order to support the local message loading services, all the error messages
  211. are captured in an XML file in the src/xercesc/NLS/ directory.
  212. There is a simple program, in the tools/NLS/Xlat/ directory,
  213. which can translate that text in various formats. It currently
  214. supports a simple 'in memory' format (i.e. an array of
  215. strings), the Win32 resource format, and the message catalog
  216. format. The 'in memory' format is intended for very simple
  217. installations or for use when porting to a new platform (since
  218. you can use it until you can get your own local message
  219. loading support done.)</p>
  220. <p>In the src/xercesc/util/ directory, there is an XMLMsgLoader
  221. class. This is an abstraction from which any number of
  222. message loading services can be derived. Your platform driver
  223. file can create whichever type of message loader it wants to
  224. use on that platform. &XercesCName; currently has versions for the in
  225. memory format, the Win32 resource format, the message
  226. catalog format, and ICU message loader.
  227. Some of the platforms can support multiple message
  228. loaders, in which case a #define token is used to control
  229. which one is used. You can set this in your build projects to
  230. control the message loader type used.</p>
  231. </s2>
  232. <anchor name="PluggableTranscoders"/>
  233. <s2 title="Pluggable Transcoders">
  234. <p>&XercesCName; also supports pluggable transcoding services. The
  235. XMLTransService class is an abstract API that can be derived
  236. from, to support any desired transcoding
  237. service. XMLTranscoder is the abstract API for a particular
  238. instance of a transcoder for a particular encoding. The
  239. platform driver file decides what specific type of transcoder
  240. to use, which allows each platform to use its native
  241. transcoding services, or the ICU service if desired.</p>
  242. <p>Implementations are provided for Win32 native services, ICU
  243. services, and the <ref>iconv</ref> services available on many
  244. Unix platforms. The Win32 version only provides native code
  245. page services, so it can only handle XML code in the intrinsic
  246. encodings ASCII, UTF-8, UTF-16 (Big/Small Endian), UCS4
  247. (Big/Small Endian), EBCDIC code pages IBM037, IBM1047 and
  248. IBM1140 encodings, ISO-8859-1 (aka Latin1) and Windows-1252. The ICU version
  249. provides all of the encodings that ICU supports. The
  250. <ref>iconv</ref> version will support the encodings supported
  251. by the local system. You can use transcoders we provide or
  252. create your own if you feel ours are insufficient in some way,
  253. or if your platform requires an implementation that &XercesCName; does not
  254. provide.</p>
  255. </s2>
  256. <anchor name="PortingGuidelines"/>
  257. <s2 title="Porting Guidelines">
  258. <p>All platform dependent code in &XercesCName; has been
  259. isolated to a couple of files, which should ease the porting
  260. effort. The <code>src/xercesc/util</code> directory
  261. contains all such files. In particular:</p>
  262. <ul>
  263. <li>The <code>src/xercesc/util/FileManagers</code> directory
  264. contains implementations of file managers for various
  265. platforms.</li>
  266. <li>The <code>src/xercesc/util/MutexManagers</code> directory
  267. contains implementations of mutex managers for various
  268. platforms.</li>
  269. <li>The <code>src/xercesc/util/Xerces_autoconf_const*</code> files
  270. provide base definitions for various platforms.</li>
  271. </ul>
  272. <p>Other concerns are:</p>
  273. <ul>
  274. <li>Does ICU compile on your platform? If not, then you'll need to
  275. create a transcoder implementation that uses your local transcoding
  276. services. The iconv transcoder should work for you, though perhaps
  277. with some modifications.</li>
  278. <li>What message loader will you use? To get started, you can use the
  279. "in memory" one, which is very simple and easy. Then, once you get
  280. going, you may want to adapt the message catalog message loader, or
  281. write one of your own that uses local services.</li>
  282. <li>What should I define XMLCh to be? Please refer to <jump
  283. href="build-misc-&XercesC3Series;.html#XMLChInfo">What should I define XMLCh to be?</jump> for
  284. further details.</li>
  285. </ul>
  286. <p>Finally, you need to decide about how to define XMLCh. Generally,
  287. XMLCh should be defined to be a type suitable for holding a
  288. utf-16 encoded (16 bit) value, usually an <code>unsigned short</code>. </p>
  289. <p>All XML data is handled within &XercesCName; as strings of
  290. XMLCh characters. Regardless of the size of the
  291. type chosen, the data stored in variables of type XMLCh
  292. will always be utf-16 encoded values. </p>
  293. <p>Unlike XMLCh, the encoding
  294. of wchar_t is platform dependent. Sometimes it is utf-16
  295. (AIX, Windows), sometimes ucs-4 (Solaris,
  296. Linux), sometimes it is not based on Unicode at all
  297. (HP/UX, AS/400, system 390). </p>
  298. <p>Some earlier releases of &XercesCName; defined XMLCh to be the
  299. same type as wchar_t on most platforms, with the goal of making
  300. it possible to pass XMLCh strings to library or system functions
  301. that were expecting wchar_t parameters. This approach has
  302. been abandoned because of</p>
  303. <ul>
  304. <li>
  305. Portability problems with any code that assumes that
  306. the types of XMLCh and wchar_t are compatible
  307. </li>
  308. <li>Excessive memory usage, especially in the DOM, on
  309. platforms with 32 bit wchar_t.
  310. </li>
  311. <li>utf-16 encoded XMLCh is not always compatible with
  312. ucs-4 encoded wchar_t on Solaris and Linux. The
  313. problem occurs with Unicode characters with values
  314. greater than 64k; in ucs-4 the value is stored as
  315. a single 32 bit quantity. With utf-16, the value
  316. will be stored as a "surrogate pair" of two 16 bit
  317. values. Even with XMLCh equated to wchar_t, xerces will
  318. still create the utf-16 encoded surrogate pairs, which
  319. are illegal in ucs-4 encoded wchar_t strings.
  320. </li>
  321. </ul>
  322. </s2>
  323. <anchor name="CPPNamespace"/>
  324. <s2 title="Using C++ Namespace">
  325. <p>&XercesCName; makes use of C++ namespace to make sure its
  326. definitions do not conflict with other libraries and
  327. applications. As a result applications must
  328. namespace-qualify all &XercesCName; classes, data and
  329. variables using the <code>xercesc</code> name. Alternatively,
  330. applications can use <code>using xercesc::&lt;Name>;</code>
  331. declarations
  332. to make individual &XercesCName; names visible in the
  333. current scope
  334. or <code>using namespace xercesc;</code>
  335. definition to make all &XercesCName; names visible in the
  336. current scope.</p>
  337. <p>While the above information should be sufficient for the majority
  338. of applications, for cases where several versions of the &XercesCName;
  339. library must be used in the same application, namespace versioning is
  340. provided. The following convenience macros can be used to access the
  341. &XercesCName; namespace names with versions embedded
  342. (see <code>src/xercesc/util/XercesDefs.hpp</code>):</p>
  343. <source>
  344. #define XERCES_CPP_NAMESPACE_BEGIN namespace &XercesC3NSVersion; {
  345. #define XERCES_CPP_NAMESPACE_END }
  346. #define XERCES_CPP_NAMESPACE_USE using namespace &XercesC3NSVersion;;
  347. #define XERCES_CPP_NAMESPACE_QUALIFIER &XercesC3NSVersion;::
  348. namespace &XercesC3NSVersion; { }
  349. namespace &XercesC3Namespace; = &XercesC3NSVersion;;
  350. </source>
  351. </s2>
  352. <anchor name="SpecifyLocaleForMessageLoader"/>
  353. <s2 title="Specify Locale for Message Loader">
  354. <p>&XercesCName; provides mechanisms for Native Language Support (NLS).
  355. Even though
  356. the current distribution has only English message file, it is capable
  357. of supporting other languages once the translated version of the
  358. target language is available.</p>
  359. <p>An application can specify the locale for the message loader in their
  360. very first invocation to XMLPlatformUtils::Initialize() by supplying
  361. a parameter for the target locale intended. The default locale is "en_US".
  362. </p>
  363. <source>
  364. // Initialize the parser system
  365. try
  366. {
  367. XMLPlatformUtils::Initialize("fr_FR");
  368. }
  369. catch ()
  370. {
  371. }
  372. </source>
  373. </s2>
  374. <anchor name="SpecifyLocationForMessageLoader"/>
  375. <s2 title="Specify Location for Message Loader">
  376. <p>&XercesCName; searches for message files at the location
  377. specified in the <code>XERCESC_NLS_HOME</code> environment
  378. variable and, if that is not set, at the default
  379. message directory, <code>$XERCESCROOT/msg</code>.
  380. </p>
  381. <p>Application can specify an alternative location for the message files in their
  382. very first invocation to XMLPlatformUtils::Initialize() by supplying
  383. a parameter for the alternative location.
  384. </p>
  385. <source>
  386. // Initialize the parser system
  387. try
  388. {
  389. XMLPlatformUtils::Initialize("en_US", "/usr/nls");
  390. }
  391. catch ()
  392. {
  393. }
  394. </source>
  395. </s2>
  396. <anchor name="PluggablePanicHandler"/>
  397. <s2 title="Pluggable Panic Handler">
  398. <p>&XercesCName; reports panic conditions encountered to the panic
  399. handler installed. The panic handler can take whatever action
  400. appropriate to handle the panic condition.
  401. </p>
  402. <p>&XercesCName; allows application to provide a customized panic handler
  403. (class implementing the interface PanicHandler), in its very first invocation of
  404. XMLPlatformUtils::Initialize().
  405. </p>
  406. <p>In the absence of an application-specific panic handler, &XercesCName; default
  407. panic handler is installed and used, which aborts program whenever a panic
  408. condition is encountered.
  409. </p>
  410. <source>
  411. // Initialize the parser system
  412. try
  413. {
  414. PanicHandler* ph = new MyPanicHandler();
  415. XMLPlatformUtils::Initialize("en_US",
  416. "/usr/nls",
  417. ph);
  418. }
  419. catch ()
  420. {
  421. }
  422. </source>
  423. </s2>
  424. <anchor name="PluggableMemoryManager"/>
  425. <s2 title="Pluggable Memory Manager">
  426. <p>Certain applications wish to maintain precise control over
  427. memory allocation. This enables them to recover more easily
  428. from crashes of individual components, as well as to allocate
  429. memory more efficiently than a general-purpose OS-level
  430. procedure with no knowledge of the characteristics of the
  431. program making the requests for memory. In &XercesCName; this
  432. is supported via the Pluggable Memory Handler.
  433. </p>
  434. <p>Users who wish to implement their own MemoryManager,
  435. an interface found in <code>xercesc/framework/MemoryManager.hpp</code>,
  436. need to implement only two methods:</p>
  437. <source>
  438. // This method allocates requested memory.
  439. // the parameter is the requested memory size
  440. // A pointer to the allocated memory is returned.
  441. virtual void* allocate(XMLSize_t size) = 0;
  442. // This method deallocates memory
  443. // The parameter is a pointer to the allocated memory to be deleted
  444. virtual void deallocate(void* p) = 0;
  445. </source>
  446. <p>To maximize the amount of flexibility that applications
  447. have in terms of controlling memory allocation, a
  448. MemoryManager instance may be set as part of the call to
  449. XMLPlatformUtils::Initialize() to allow for static
  450. initialization to be done with the given MemoryHandler; a
  451. (possibly different) MemoryManager may be passed in to the
  452. constructors of all Xerces parser objects as well, and all
  453. dynamic allocations within the parsers will make use of this
  454. object. Assuming that MyMemoryHandler is a class that
  455. implements the MemoryManager interface, here is a bit of
  456. pseudocode which illustrates these ideas:
  457. </p>
  458. <source>
  459. MyMemoryHandler *mm_for_statics = new MyMemoryHandler();
  460. MyMemoryHandler *mm_for_particular_parser = new MyMemoryManager();
  461. // initialize the parser information; try/catch
  462. // removed for brevity
  463. XMLPlatformUtils::Initialize(XMLUni::fgXercescDefaultLocale, 0,0,
  464. mm_for_statics);
  465. // create a parser object
  466. XercesDOMParser *parser = new
  467. XercesDomParser(mm_for_particular_parser);
  468. // ...
  469. delete parser;
  470. XMLPlatformUtils::Terminate();
  471. </source>
  472. <p>
  473. If a user provides a MemoryManager object to the parser, then
  474. the user owns that object. It is also important to note that
  475. &XercesCName; default implementation simply uses the global
  476. new and delete operators.
  477. </p>
  478. </s2>
  479. <anchor name="SecurityManager"/>
  480. <s2 title="Managing Security Vulnerabilities">
  481. <p>
  482. The purpose of the SecurityManager class is to permit applications a
  483. means to have the parser reject documents whose processing would
  484. otherwise consume large amounts of system resources. Malicious
  485. use of such documents could be used to launch a denial-of-service
  486. attack against a system running the parser. Initially, the
  487. SecurityManager only knows about attacks that can result from
  488. exponential entity expansion; this is the only known attack that
  489. involves processing a single XML document. Other, similar attacks
  490. can be launched if arbitrary schemas may be parsed; there already
  491. exist means (via use of the EntityResolver interface) by which
  492. applications can deny processing of untrusted schemas. In future,
  493. the SecurityManager will be expanded to take these other exploits
  494. into account.
  495. </p>
  496. <p>
  497. The SecurityManager class is very simple: It will contain
  498. getters and setters corresponding to each known variety of
  499. exploit. These will reflect limits that the application may
  500. impose on the parser with respect to the processing of various
  501. XML constructs. When an instance of SecurityManager is
  502. instantiated, default values for these limits will be provided
  503. that should suit most applications.
  504. </p>
  505. <p>
  506. By default, &XercesCName; is a wholly conformant XML parser; that
  507. is, no security-related considerations will be observed by
  508. default. An application must provide an instance of the
  509. SecurityManager class to a parser in order to make that
  510. parser behave in a security-conscious manner. For example:
  511. </p>
  512. <source>
  513. SAXParser *myParser = new SAXParser();
  514. SecurityManager *myManager = new SecurityManager();
  515. myManager->setEntityExpansionLimit(100000); // larger than default
  516. myParser->setSecurityManager(myManager);
  517. // ... use the parser
  518. </source>
  519. <p>
  520. Note that SecurityManager instances may be set on all kinds of
  521. &XercesCName; parsers; please see the documentation for the
  522. individual parsers for details.
  523. </p>
  524. <p>
  525. Note also that the application always owns the SecurityManager
  526. instance. The default SecurityManager that &XercesCName; provides
  527. is not thread-safe; although it only uses primitive operations at
  528. the moment, users may need to extend the class with a
  529. thread-safe implementation on some platforms.
  530. </p>
  531. </s2>
  532. <anchor name="UseSpecificScanner"/>
  533. <s2 title="Use Specific Scanner">
  534. <p>For performance and modularity &XercesCName; provides a mechanism
  535. for specifying the scanner to be used when scanning an XML document.
  536. Such mechanism will enable the creation of special purpose scanners
  537. that can be easily plugged in.</p>
  538. <p>&XercesCName; supports the following scanners:</p>
  539. <s3 title="WFXMLScanner">
  540. <p>
  541. The WFXMLScanner is a non-validating scanner which performs well-formedness check only.
  542. It does not do any DTD/XMLSchema processing. If the XML document contains a DOCTYPE, it
  543. will be silently ignored (i.e. no warning message is issued). Similarly, any schema
  544. specific attributes (e.g. schemaLocation), will be treated as normal element attributes.
  545. Setting grammar specific features/properties will have no effect on its behavior
  546. (e.g. setLoadExternalDTD(true) is ignored).
  547. </p>
  548. <source>
  549. // Create a DOM parser
  550. XercesDOMParser parser;
  551. // Specify scanner name
  552. parser.useScanner(XMLUni::fgWFXMLScanner);
  553. // Specify other parser features, e.g.
  554. parser.setDoNamespaces(true);
  555. </source>
  556. </s3>
  557. <s3 title="DGXMLScanner">
  558. <p>
  559. The DGXMLScanner handles XML documents with DOCTYPE information. It does not do any
  560. XMLSchema processing, which means that any schema specific attributes (e.g. schemaLocation),
  561. will be treated as normal element attributes. Setting schema grammar specific features/properties
  562. will have no effect on its behavior (e.g. setDoSchema(true) and setLoadSchema(true) are ignored).
  563. </p>
  564. <source>
  565. // Create a SAX parser
  566. SAXParser parser;
  567. // Specify scanner name
  568. parser.useScanner(XMLUni::fgDGXMLScanner);
  569. // Specify other parser features, e.g.
  570. parser.setLoadExternalDTD(true);
  571. </source>
  572. </s3>
  573. <s3 title="SGXMLScanner">
  574. <p>
  575. The SGXMLScanner handles XML documents with XML schema grammar information.
  576. If the XML document contains a DOCTYPE, it will be ignored. Namespace and
  577. schema processing features are on by default, and setting them to off has
  578. not effect.
  579. </p>
  580. <source>
  581. // Create a SAX2 parser
  582. SAX2XMLReader* parser = XMLReaderFactory::createXMLReader();
  583. // Specify scanner name
  584. parser->setProperty(XMLUni::fgXercesScannerName, (void *)XMLUni::fgSGXMLScanner);
  585. // Specify other parser features, e.g.
  586. parser->setFeature(XMLUni::fgXercesSchemaFullChecking, false);
  587. </source>
  588. </s3>
  589. <s3 title="IGXMLScanner">
  590. <p>
  591. The IGXMLScanner is an integrated scanner and handles XML documents with DTD and/or
  592. XML schema grammar. This is the default scanner used by the various parsers if no
  593. scanner is specified.
  594. </p>
  595. <source>
  596. // Create a DOMLSParser parser
  597. DOMLSParser *parser = ((DOMImplementationLS*)impl)->createLSParser(
  598. DOMImplementationLS::MODE_SYNCHRONOUS, 0);
  599. // Specify scanner name - This is optional as IGXMLScanner is the default
  600. parser->getDomConfig()->setParameter(
  601. XMLUni::fgXercesScannerName, (void *)XMLUni::fgIGXMLScanner);
  602. // Specify other parser features, e.g.
  603. parser->getDomConfig()->setParameter(XMLUni::fgDOMNamespaces, doNamespaces);
  604. parser->getDomConfig()->setParameter(XMLUni::fgXercesSchema, doSchema);
  605. </source>
  606. </s3>
  607. </s2>
  608. </s1>