Newer
Older
<?xml version="1.0" standalone="no"?>
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
-->
<!DOCTYPE s1 SYSTEM "sbk:/style/dtd/document.dtd">
<s1 title="DOM Programming Guide">
<anchor name="Objectives"/>
<s2 title="Design Objectives">
<p>The C++ DOM implementation is based on the
<jump href="ApacheDOMC++Binding.html">Apache Recommended DOM C++ binding</jump>.</p>
<p>The design objective aims at meeting the following requirements:
</p>
<ul>
<li>Reduced memory footprint.</li>
<li>Fast - especially for use in server style and multi-threaded applications.</li>
<li>Good scalability on multiprocessor systems.</li>
<li>More C++ like and less Java like.</li>
</ul>
</s2>
<anchor name="DOM3"/>
<s2 title="DOM Level 3 Support in &XercesCName;">
Alberto Massari
committed
<p>The &XercesCName; &XercesC3Version; contains an implementation of the W3C DOM Level 3 as specified in </p>
<ul>
<li><jump href="http://www.w3.org/TR/DOM-Level-3-Core/">
DOM Level 3.0 Core Specification</jump>, Version 1.0 W3C Recommendation 07 April 2004 and</li>
<li> <jump href="http://www.w3.org/TR/DOM-Level-3-LS/">
Document Object Model (DOM) Level 3 Load and Save Specification</jump>,
Version 1.0 W3C Recommendation 07 April 2004</li>
</ul>
<s3 title='Implementation of DOM Level 3 Core'>
<p>The following are NOT implemented in &XercesCName; &XercesC3Version;.</p>
<ul>
<li>
<code>DOMError</code>: setRelatedException
</li>
<li>
<code>DOMImplementation</code>: createLSParser(MODE_ASYNCHRONOUS)
</li>
<li>
<code>DOMTypeInfo</code>: isDerivedFrom()
</li>
</ul>
</s3>
</s2>
<anchor name="UsingDOMAPI"/>
<s2 title="Using DOM API">
<anchor name="AccessAPI"/>
<s3 title="Accessing API from application code">
<source>
#include <xercesc/dom/DOM.hpp></source>
<p>The header file <dom/DOM.hpp> includes all the
individual headers for the DOM API classes. </p>
</s3>
<anchor name="DOMClassNames"/>
<s3 title="Class Names">
<p>
The DOM class names are prefixed with "DOM" (if not already), e.g. "DOMNode". The intent is
to prevent conflicts between DOM class names and other names
that may already be in use by an application or other
libraries that a DOM based application must link with.</p>
<source>
DOMDocument* myDocument;
DOMNode* aNode;
DOMText* someText;
</source>
</s3>
<anchor name="DOMObjMgmt"/>
<s3 title="Objects Management">
<p>Applications would use normal C++ pointers to directly access the
implementation objects for Nodes in C++ DOM.
</p>
<p>Consider the following code snippets</p>
<source>
DOMNode* aNode;
DOMNode* docRootNode;
aNode = someDocument->createElement(anElementName);
docRootNode = someDocument->getDocumentElement();
docRootNode->appendChild(aNode);
</source>
</s3>
<anchor name="DOMMemMgmt"/>
<s3 title="Memory Management">
<p>The C++ DOM implementation provides a release() method for releasing any "orphaned"
resources that were created through createXXXX factory method.
Memory for any returned object are owned by implementation. Please see
<jump href="ApacheDOMC++Binding.html#release"> Apache Recommended DOM C++ binding</jump>
for details.</p>
<s4 title="Objects created by DOMImplementation::createXXXX">
<p>Users <em>must</em> call the release() function when finished using any objects that
were created by the DOMImplementation::createXXXX (e.g. DOMLSParser, DOMLSSerializer, DOMLSInput, DOMLSOutput, DOMDocument,
DOMDocumentType).</p>
<p>Access to a released object will lead to unexpected behaviour.</p>
<note>When a DOMDocument is released, all its associated children AND any objects it owned
(e.g. DOMRange, DOMTreeWalker, DOMNodeIterator or any orphaned nodes) will also be released.
</note>
<note>When a DOMDocument is cloned, the cloned document has nothing related to the original
master document and need to be released explicitly.
</note>
Tinny Ng
committed
<note>When a DOMDocumentType has been inserted into a DOMDocument and thus has a owner,
it will then be released automatically when its owner document is released.
DOMException::INVALID_ACCESS_ERR will be raised if releasing such owned node.
</note>
</s4>
<s4 title="Objects created by DOMDocument::createXXXX">
<p>Users <em>can</em> call the release() function to indicate the release of any orphaned nodes.
When an orphaned Node is released, its associated children will also be released.
Access to a released Node will lead to unexpected behaviour. These orphaned Nodes will
eventually be released, if not already done so, when its owner document is released</p>
Tinny Ng
committed
<note>DOMException::INVALID_ACCESS_ERR will be raised if releasing a Node that has a parent
(has a owner).</note>
</s4>
<s4 title="Objects created by DOMDocumentRange::createRange or DOMDocumentTraversal::createXXXX">
<p>Users <em>can</em> call release() function when finished using the DOMRange,
DOMNodeIterator, DOMTreeWalker.
Access to a released object will lead to unexpected behaviour. These objects will
Tinny Ng
committed
eventually be released, if not already done so, when its owner document is released
</p>
</s4>
<p>Here is an example</p>
<source>
//
// Create a small document tree
//
{
XMLString::transcode("Range", tempStr, 99);
DOMImplementation* impl = DOMImplementationRegistry::getDOMImplementation(tempStr, 0);
XMLString::transcode("root", tempStr, 99);
DOMDocument* doc = impl->createDocument(0, tempStr, 0);
DOMElement* root = doc->getDocumentElement();
XMLString::transcode("FirstElement", tempStr, 99);
DOMElement* e1 = doc->createElement(tempStr);
root->appendChild(e1);
XMLString::transcode("SecondElement", tempStr, 99);
DOMElement* e2 = doc->createElement(tempStr);
root->appendChild(e2);
XMLString::transcode("aTextNode", tempStr, 99);
DOMText* textNode = doc->createTextNode(tempStr);
e1->appendChild(textNode);
// optionally, call release() to release the resource associated with the range after done
DOMRange* range = doc->createRange();
range->release();
// removedElement is an orphaned node, optionally call release() to release associated resource
DOMElement* removedElement = root->removeChild(e2);
removedElement->release();
// no need to release this returned object which is owned by implementation
XMLString::transcode("*", tempStr, 99);
DOMNodeList* nodeList = doc->getElementsByTagName(tempStr);
// done with the document, must call release() to release the entire document resources
doc->release();
</source>
</s3>
<anchor name="XMLCh"/>
<s3 title="String Type">
<p>The C++ DOM uses the plain, null-terminated (XMLCh *) utf-16 strings
as the String type. The (XMLCh*) utf-16 type string has low overhead.</p>
<source>
//C++ DOM
const XMLCh* nodeValue = aNode->getNodeValue();
</source>
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
<p>All the string data would remain in memory until the document object is released.
But such string data may be RECYCLED by the implementation if necessary.
Users should make appropriate copy of any returned string for safe reference.</p>
<p>For example after a DOMNode has been released, the memory allocated for its node value
will be recycled by the implementation. </p>
<source>
XMLCh xfoo[] = {chLatin_f, chLatin_o, chLatin_o, chNull};
// pAttr has node value = "foo"
// fNodeValue has "foo"
pAttr->setNodeValue(xfoo);
const XMLCh* fNodeValue = pAttr->getNodeValue();
// fNodeValue has "foo"
// make a copy of the string for future reference
XMLCh* oldNodeValue = XMLString::replicate(fNodeValue);
// release the node pAttr
pAttr->release()
// other operations
:
:
// implementation may have recycled the memory of the pAttr already
// so it's not safe to expect fNodeValue still have "foo"
if (XMLString::compareString(xfoo, fNodeValue))
printf("fNodeValue has some other content\n");
// should use your own safe copy
if (!XMLString::compareString(xfoo, oldNodeValue))
printf("Use your own copy of the oldNodeValue if want to reference the string later\n");
// delete your own replicated string when done
XMLString::release(&oldNodeValue);
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
</source>
<p>Or if DOMNode::setNodeValue() is called to set a new node value,
the implementation will simply overwrite the node value memory area. So any previous
pointers will now have the new value automatically. Users should make appropriate
copy of any previous returned string for safe reference. For example</p>
<source>
XMLCh xfoo[] = {chLatin_f, chLatin_o, chLatin_o, chNull};
XMLCh xfee[] = {chLatin_f, chLatin_e, chLatin_e, chNull};
// pAttr has node value = "foo"
pAttr->setNodeValue(xfoo);
const XMLCh* fNodeValue = pAttr->getNodeValue();
// fNodeValue has "foo"
// make a copy of the string for future reference
XMLCh* oldNodeValue = XMLString::replicate(fNodeValue);
// now set pAttr with a new node value "fee"
pAttr->setNodeValue(xfee);
// should not rely on fNodeValue for the old node value, it may not compare
if (XMLString::compareString(xfoo, fNodeValue))
printf("Should not rely on fNodeValue for the old node value\n");
// should use your own safe copy
if (!XMLString::compareString(xfoo, oldNodeValue))
printf("Use your own copy of the oldNodeValue if want to reference the string later\n");
// delete your own replicated string when done
XMLString::release(&oldNodeValue);
</source>
<p>This is to prevent memory growth when DOMNode::setNodeValue() is being called hundreds of
times. This design allows users to actively select which returned string should stay
in memory by manually copying the string to application's own heap.</p>
</s3>
</s2>
<anchor name="XercesDOMParser"/>
<s2 title="XercesDOMParser">
<anchor name="ConstructXercesDOMParser"/>
<s3 title="Constructing a XercesDOMParser">
<p>In order to use &XercesCName; to parse XML files using DOM, you
can create an instance of the XercesDOMParser class. The example
below shows the code you need in order to create an instance of the
XercesDOMParser.</p>
<source>
#include <xercesc/parsers/XercesDOMParser.hpp>
#include <xercesc/dom/DOM.hpp>
#include <xercesc/sax/HandlerBase.hpp>
#include <xercesc/util/XMLString.hpp>
#include <xercesc/util/PlatformUtils.hpp>
Boris Kolpackov
committed
using namespace std;
using namespace xercesc;
int main (int argc, char* args[]) {
try {
XMLPlatformUtils::Initialize();
}
catch (const XMLException& toCatch) {
char* message = XMLString::transcode(toCatch.getMessage());
cout << "Error during initialization! :\n"
<< message << "\n";
return 1;
}
XercesDOMParser* parser = new XercesDOMParser();
Boris Kolpackov
committed
parser->setValidationScheme(XercesDOMParser::Val_Always);
parser->setDoNamespaces(true); // optional
ErrorHandler* errHandler = (ErrorHandler*) new HandlerBase();
parser->setErrorHandler(errHandler);
char* xmlFile = "x1.xml";
try {
parser->parse(xmlFile);
}
catch (const XMLException& toCatch) {
char* message = XMLString::transcode(toCatch.getMessage());
cout << "Exception message is: \n"
<< message << "\n";
return -1;
}
catch (const DOMException& toCatch) {
char* message = XMLString::transcode(toCatch.msg);
cout << "Exception message is: \n"
<< message << "\n";
return -1;
}
catch (...) {
cout << "Unexpected Exception \n" ;
return -1;
}
delete parser;
delete errHandler;
return 0;
</source>
</s3>
<anchor name="XercesDOMFeatures"/>
<s3 title="XercesDOMParser Supported Features">
<p>The behavior of the XercesDOMParser is dependent on the values of the following features. All
of the features below are set using the "setter" methods (e.g. <code>setDoNamespaces</code>),
and are queried using the corresponding "getter" methods (e.g. <code>getDoNamespaces</code>).
The following only gives you a quick summary of supported features. Please
Boris Kolpackov
committed
refer to <jump href="api-&XercesC3Series;.html">API Documentation</jump> for complete detail.
</p>
<anchor name="createEntityRef"/>
<table>
<tr><th colspan="2"><em>void setCreateEntityReferenceNodes(const bool)</em></th></tr>
<tr><th><em>true:</em></th><td> Create EntityReference nodes in the DOM tree. The
EntityReference nodes and their child nodes will be read-only. </td></tr>
<tr><th><em>false:</em></th><td> Do not create EntityReference nodes in the DOM tree. No
EntityReference nodes will be created, only the nodes corresponding to their fully
expanded substitution text will be created. </td></tr>
<tr><th><em>default:</em></th><td> true </td></tr>
<tr><th><em>note:</em></th><td> This feature only affects the appearance of
EntityReference nodes in the DOM tree. The document will always contain the entity
reference child nodes. </td></tr>
</table>
<p/>
<table>
<tr><th colspan="2"><em>void setIncludeIgnorableWhitespace(const bool)</em></th></tr>
<tr><th><em>true:</em></th><td> Include text nodes that can be considered "ignorable
<tr><th><em>false:</em></th><td> Do not include ignorable whitespace in the DOM tree. </td></tr>
<tr><th><em>default:</em></th><td> true </td></tr>
<tr><th><em>note:</em></th><td> The only way that the parser can determine if text is
ignorable is by reading the associated grammar and having a content model for the
document. When ignorable whitespace text nodes are included in the DOM tree,
they will be flagged as ignorable; and the method DOMText::isIgnorableWhitespace()
will return true for those text nodes. </td></tr>
</table>
<p/>
<anchor name="namespaces"/>
<table>
<tr><th colspan="2"><em>void setDoNamespaces(const bool)</em></th></tr>
<tr><th><em>true:</em></th><td> Perform Namespace processing. </td></tr>
<tr><th><em>false:</em></th><td> Do not perform Namespace processing. </td></tr>
<tr><th><em>default:</em></th><td> false </td></tr>
<tr><th><em>note:</em></th><td> If the validation scheme is set to Val_Always or Val_Auto, then the
document must contain a grammar that supports the use of namespaces. </td></tr>
<tr><th><em>see:</em></th><td>
<link anchor="validation-dynamic">setValidationScheme</link>
</td></tr>
</table>
<p/>
<anchor name="validation-dynamic"/>
<table>
<tr><th colspan="2"><em>void setValidationScheme(const ValSchemes)</em></th></tr>
<tr><th><em>Val_Auto:</em></th><td> The parser will report validation errors only if a grammar is specified.</td></tr>
<tr><th><em>Val_Always:</em></th><td> The parser will always report validation errors. </td></tr>
<tr><th><em>Val_Never:</em></th><td> Do not report validation errors. </td></tr>
<tr><th><em>default:</em></th><td> Val_Never </td></tr>
<tr><th><em>note:</em></th><td> If set to Val_Always, the document must
specify a grammar. If this feature is set to Val_Never and document specifies a grammar,
that grammar might be parsed but no validation of the document contents will be
performed. </td></tr>
<tr><th><em>see:</em></th><td>
<link anchor="load-external-dtd">setLoadExternalDTD</link>
</td></tr>
</table>
<p/>
<anchor name="schema"/>
<table>
<tr><th colspan="2"><em>void setDoSchema(const bool)</em></th></tr>
<tr><th><em>true:</em></th><td> Enable the parser's schema support. </td></tr>
<tr><th><em>false:</em></th><td> Disable the parser's schema support. </td></tr>
<tr><th><em>default:</em></th><td> false </td></tr>
<tr><th><em>note</em></th><td> If set to true, namespace processing must also be turned on. </td></tr>
<tr><th><em>see:</em></th><td>
<link anchor="namespaces">setDoNamespaces</link>
</td></tr>
</table>
<p/>
<table>
<tr><th colspan="2"><em>void setValidationSchemaFullChecking(const bool)</em></th></tr>
<tr><th><em>true:</em></th><td> Enable full schema constraint checking, including checking
which may be time-consuming or memory intensive. Currently, particle unique
attribution constraint checking and particle derivation restriction checking
are controlled by this option. </td></tr>
<tr><th><em>false:</em></th><td> Disable full schema constraint checking. </td></tr>
<tr><th><em>default:</em></th><td> false </td></tr>
<tr><th><em>note:</em></th><td> This feature checks the Schema grammar itself for
additional errors that are time-consuming or memory intensive. It does <em>not</em> affect the
level of checking performed on document instances that use Schema grammars.</td></tr>
<tr><th><em>see:</em></th><td>
<link anchor="schema">setDoSchema</link>
</td></tr>
</table>
<p/>
<anchor name="load-schema"/>
<table>
<tr><th colspan="2"><em>void setLoadSchema(const bool)</em></th></tr>
<tr><th><em>true:</em></th><td> Load the schema. </td></tr>
<tr><th><em>false:</em></th><td> Don't load the schema if it wasn't found in the grammar pool. </td></tr>
<tr><th><em>default:</em></th><td> true </td></tr>
<tr><th><em>note:</em></th><td> This feature is ignored and no schemas are loaded if schema processing is disabled. </td></tr>
<tr><th><em>see:</em></th><td>
<link anchor="schema">setDoSchema</link>
</td></tr>
</table>
<p/>
<tr><th colspan="2"><em>void setLoadExternalDTD(const bool)</em></th></tr>
<tr><th><em>true:</em></th><td> Load the External DTD . </td></tr>
<tr><th><em>false:</em></th><td> Ignore the external DTD completely. </td></tr>
<tr><th><em>default:</em></th><td> true </td></tr>
<tr><th><em>note</em></th><td> This feature is ignored and DTD is always loaded
if the validation scheme is set to Val_Always or Val_Auto. </td></tr>
<tr><th><em>see:</em></th><td>
<link anchor="validation-dynamic">setValidationScheme</link>
</td></tr>
</table>
<p/>
<anchor name="continue-after-fatal"/>
<table>
<tr><th colspan="2"><em>void setExitOnFirstFatalError(const bool)</em></th></tr>
<tr><th><em>true:</em></th><td> Stops parse on first fatal error. </td></tr>
<tr><th><em>false:</em></th><td> Attempt to continue parsing after a fatal error. </td></tr>
<tr><th><em>default:</em></th><td> true </td></tr>
<tr><th><em>note:</em></th><td> The behavior of the parser when this feature is set to
false is <em>undetermined</em>! Therefore use this feature with extreme caution because
the parser may get stuck in an infinite loop or worse.</td></tr>
</table>
<p/>
<table>
<tr><th colspan="2"><em>void setValidationConstraintFatal(const bool)</em></th></tr>
<tr><th><em>true:</em></th><td> The parser will treat validation error as fatal and will
exit depends on the state of
<link anchor="continue-after-fatal">setExitOnFirstFatalError</link>
</td></tr>
<tr><th><em>false:</em></th><td> The parser will report the error and continue processing. </td></tr>
<tr><th><em>default:</em></th><td> false </td></tr>
<tr><th><em>note:</em></th><td> Setting this true does not mean the validation error will
be printed with the word "Fatal Error". It is still printed as "Error", but the parser
will exit if
<link anchor="continue-after-fatal">setExitOnFirstFatalError</link>
is set to true.</td></tr>
<tr><th><em>see:</em></th><td>
<link anchor="continue-after-fatal">setExitOnFirstFatalError</link>
</td></tr>
</table>
<p/>
<anchor name="use-cached"/>
<table>
<tr><th colspan="2"><em>void useCachedGrammarInParse(const bool)</em></th></tr>
<tr><th><em>true:</em></th><td>Use cached grammar if it exists in the pool.</td></tr>
<tr><th><em>false:</em></th><td>Parse the schema grammar.</td></tr>
<tr><th><em>default:</em></th><td> false </td></tr>
<tr><th><em>note:</em></th><td>The getter function for this method is called isUsingCachedGrammarInParse.</td></tr>
<tr><th><em>note:</em></th><td>If the grammar caching option is enabled, this option is set to true automatically and
any setting to this option by the user is a no-op.</td></tr>
<tr><th><em>see:</em></th><td>
<link anchor="cache-grammar">cacheGrammarFromParse</link>
</td></tr>
</table>
<p/>
<anchor name="cache-grammar"/>
<table>
<tr><th colspan="2"><em>void cacheGrammarFromParse(const bool)</em></th></tr>
<tr><th><em>true:</em></th><td>Cache the grammar in the pool for re-use in subsequent parses.</td></tr>
<tr><th><em>false:</em></th><td>Do not cache the grammar in the pool</td></tr>
<tr><th><em>default:</em></th><td> false </td></tr>
<tr><th><em>note:</em></th><td>The getter function for this method is called isCachingGrammarFromParse</td></tr>
<tr><th><em>note:</em></th><td> If set to true, the useCachedGrammarInParse
is also set to true automatically.</td></tr>
<tr><th><em>see:</em></th><td>
<link anchor="use-cached">useCachedGrammarInParse</link>
</td></tr>
</table>
<p/>
<anchor name="StandardUriConformant"/>
<table>
<tr><th colspan="2"><em>void setStandardUriConformant(const bool)</em></th></tr>
<tr><th><em>true:</em></th><td> Force standard uri conformance. </td></tr>
<tr><th><em>false:</em></th><td> Do not force standard uri conformance. </td></tr>
<tr><th><em>default:</em></th><td> false </td></tr>
<tr><th><em>note:</em></th><td> If set to true, malformed uri will be rejected
and fatal error will be issued. </td></tr>
</table>
<p/>
<anchor name="CalculateSrcOffset"/>
<table>
<tr><th colspan="2"><em>void setCalculateSrcOfs(const bool)</em></th></tr>
<tr><th><em>true:</em></th><td> Enable source offset calculation. </td></tr>
<tr><th><em>false:</em></th><td> Disable source offset calculation. </td></tr>
<tr><th><em>default:</em></th><td> false </td></tr>
<tr><th><em>note:</em></th><td> If set to true, the user can inquire about
the current source offset within the input source. Setting it to false (default)
improves the performance.</td></tr>
</table>
<p/>
Boris Kolpackov
committed
David Abram Cargill
committed
<anchor name="IdentityConstraintChecking"/>
<table>
<tr><th colspan="2"><em>void setIdentityConstraintChecking(const bool);</em></th></tr>
<tr><th><em>true:</em></th><td> Enable identity constraint checking. </td></tr>
<tr><th><em>false:</em></th><td> Disable identity constraint checking. </td></tr>
Boris Kolpackov
committed
<tr><th><em>default:</em></th><td> true </td></tr>
David Abram Cargill
committed
</table>
<p/>
Boris Kolpackov
committed
David Abram Cargill
committed
<anchor name="GenerateSyntheticAnnotations"/>
<table>
<tr><th colspan="2"><em>void setGenerateSyntheticAnnotations(const bool);</em></th></tr>
Boris Kolpackov
committed
<tr><th><em>true:</em></th><td> Enable generation of synthetic annotations. A synthetic annotation will be
David Abram Cargill
committed
generated when a schema component has non-schema attributes but no child annotation. </td></tr>
<tr><th><em>false:</em></th><td> Disable generation of synthetic annotations. </td></tr>
Boris Kolpackov
committed
<tr><th><em>default:</em></th><td> false </td></tr>
David Abram Cargill
committed
</table>
<p/>
Boris Kolpackov
committed
David Abram Cargill
committed
<anchor name="XercesValidateAnnotations"/>
<table>
<tr><th colspan="2"><em>setValidateAnnotation</em></th></tr>
<tr><th><em>true:</em></th><td> Enable validation of annotations. </td></tr>
<tr><th><em>false:</em></th><td> Disable validation of annotations. </td></tr>
<tr><th><em>default:</em></th><td> false </td></tr>
<tr><th><em>note:</em></th><td> Each annotation is validated independently. </td></tr>
David Abram Cargill
committed
</table>
Boris Kolpackov
committed
<p/>
<anchor name="IgnoreAnnotations"/>
<table>
<tr><th colspan="2"><em>setIgnoreAnnotations</em></th></tr>
<tr><th><em>true:</em></th><td> Do not generate XSAnnotations when traversing a schema.</td></tr>
<tr><th><em>false:</em></th><td> Generate XSAnnotations when traversing a schema.</td></tr>
Boris Kolpackov
committed
<tr><th><em>default:</em></th><td> false </td></tr>
Boris Kolpackov
committed
<p/>
<anchor name="DisableDefaultEntityResolution"/>
<table>
<tr><th colspan="2"><em>setDisableDefaultEntityResolution</em></th></tr>
<tr><th><em>true:</em></th><td> The parser will not attempt to resolve the entity when the resolveEntity method returns NULL.</td></tr>
<tr><th><em>false:</em></th><td> The parser will attempt to resolve the entity when the resolveEntity method returns NULL.</td></tr>
Boris Kolpackov
committed
<tr><th><em>default:</em></th><td> false </td></tr>
</table>
<p/>
Boris Kolpackov
committed
<anchor name="SkipDTDValidation"/>
<table>
<tr><th colspan="2"><em>setSkipDTDValidation</em></th></tr>
<tr><th><em>true:</em></th><td> When schema validation is on the parser will ignore the DTD, except for entities.</td></tr>
<tr><th><em>false:</em></th><td> The parser will not ignore DTDs when validating.</td></tr>
Boris Kolpackov
committed
<tr><th><em>default:</em></th><td> false </td></tr>
<tr><th><em>see:</em></th><td>
Boris Kolpackov
committed
<link anchor="schema">DoSchema</link></td></tr>
Boris Kolpackov
committed
<p/>
David Abram Cargill
committed
<anchor name="XercesIgnoreCachedDTD"/>
Boris Kolpackov
committed
<table>
David Abram Cargill
committed
<tr><th colspan="2"><em>setIgnoreCachedDTD</em></th></tr>
Boris Kolpackov
committed
<tr><th><em>true:</em></th><td> Ignore a cached DTD when an XML document contains both an
David Abram Cargill
committed
internal and external DTD, and the use cached grammar from parse option
is enabled. Currently, we do not allow using cached DTD grammar when an
internal subset is present in the document. This option will only affect
Boris Kolpackov
committed
the behavior of the parser when an internal and external DTD both exist
David Abram Cargill
committed
in a document (i.e. no effect if document has no internal subset).</td></tr>
<tr><th><em>false:</em></th><td> Don't ignore cached DTD. </td></tr>
Boris Kolpackov
committed
<tr><th><em>default:</em></th><td> false </td></tr>
David Abram Cargill
committed
<tr><th><em>see:</em></th><td>
<link anchor="use-cached">useCachedGrammarInParse</link></td></tr>
</table>
Boris Kolpackov
committed
Boris Kolpackov
committed
<table>
<tr><th colspan="2"><em>setHandleMultipleImports</em></th></tr>
<tr><th><em>true:</em></th><td> During schema validation allow multiple schemas with the same namespace
Boris Kolpackov
committed
to be imported.</td></tr>
<tr><th><em>false:</em></th><td> Don't import multiple schemas with the same namespace. </td></tr>
Boris Kolpackov
committed
<tr><th><em>default:</em></th><td> false </td></tr>
</table>
Boris Kolpackov
committed
David Abram Cargill
committed
<anchor name="CreateSchemaInfo"/>
<table>
<tr><th colspan="2"><em>setCreateSchemaInfo</em></th></tr>
<tr><th><em>true:</em></th><td> Enable storing of PSVI information in element and attribute nodes. </td></tr>
<tr><th><em>false:</em></th><td> Disable storing of PSVI information in element and attribute nodes. </td></tr>
Boris Kolpackov
committed
<tr><th><em>default:</em></th><td> false </td></tr>
David Abram Cargill
committed
</table>
Boris Kolpackov
committed
<p/>
David Abram Cargill
committed
<anchor name="CreateCommentNodes"/>
<table>
<tr><th colspan="2"><em>setCreateCommentNodes</em></th></tr>
<tr><th><em>true:</em></th><td> Enable the parser to create comment nodes in the DOM tree being produced.</td></tr>
<tr><th><em>false:</em></th><td> Disable comment nodes being produced. </td></tr>
Boris Kolpackov
committed
<tr><th><em>default:</em></th><td> true </td></tr>
David Abram Cargill
committed
</table>
Boris Kolpackov
committed
<p/>
</s3>
<anchor name="XercesDOMProperties"/>
<s3 title="XercesDOMParser Supported Properties">
<p>The behavior of the XercesDOMParser is dependent on the values of the following properties. All
of the properties below are set using the "setter" methods (e.g. <code>setExternalSchemaLocation</code>),
and are queried using the corresponding "getter" methods (e.g. <code>getExternalSchemaLocation</code>).
The following only gives you a quick summary of supported features. Please
Boris Kolpackov
committed
refer to <jump href="api-&XercesC3Series;.html">API Documentation</jump> for
complete details.
<tr><th colspan="2"><em>void setExternalSchemaLocation(const XMLCh*)</em></th></tr>
<tr><th><em>Description</em></th><td> The XML Schema Recommendation explicitly states that
the inclusion of schemaLocation/ noNamespaceSchemaLocation attributes in the
instance document is only a hint; it does not mandate that these attributes
must be used to locate schemas. Similar situation happens to <import>
element in schema documents. This property allows the user to specify a list
of schemas to use. If the targetNamespace of a schema specified using this
method matches the targetNamespace of a schema occurring in the instance
document in schemaLocation attribute, or
if the targetNamespace matches the namespace attribute of <import>
element, the schema specified by the user using this property will
be used (i.e., the schemaLocation attribute in the instance document
or on the <import> element will be effectively ignored).</td></tr>
<tr><th><em>Value</em></th><td> The syntax is the same as for schemaLocation attributes
in instance documents: e.g, "http://www.example.com file_name.xsd".
The user can specify more than one XML Schema in the list.</td></tr>
<tr><th><em>Value Type</em></th><td> XMLCh* </td></tr>
<tr><th colspan="2"><em>void setExternalNoNamespaceSchemaLocation(const XMLCh* const)</em></th></tr>
<tr><th><em>Description</em></th><td> The XML Schema Recommendation explicitly states that
the inclusion of schemaLocation/ noNamespaceSchemaLocation attributes in the
instance document is only a hint; it does not mandate that these attributes
must be used to locate schemas. This property allows the user to specify the
no target namespace XML Schema Location externally. If specified, the instance
document's noNamespaceSchemaLocation attribute will be effectively ignored.</td></tr>
<tr><th><em>Value</em></th><td> The syntax is the same as for the noNamespaceSchemaLocation
attribute that may occur in an instance document: e.g."file_name.xsd".</td></tr>
<tr><th><em>Value Type</em></th><td> XMLCh* </td></tr>
<table>
<tr><th colspan="2"><em>void useScanner(const XMLCh* const)</em></th></tr>
<tr><th><em>Description</em></th><td> This property allows the user to specify the name of
the XMLScanner to use for scanning XML documents. If not specified, the default
scanner "IGXMLScanner" is used.</td></tr>
<tr><th><em>Value</em></th><td> The recognized scanner names are: <br/>
1."WFXMLScanner" - scanner that performs well-formedness checking only.<br/>
2. "DGXMLScanner" - scanner that handles XML documents with DTD grammar information.<br/>
3. "SGXMLScanner" - scanner that handles XML documents with XML schema grammar information.<br/>
4. "IGXMLScanner" - scanner that handles XML documents with DTD or/and XML schema grammar information.<br/>
Users can use the predefined constants defined in XMLUni directly (fgWFXMLScanner, fgDGXMLScanner,
fgSGXMLScanner, or fgIGXMLScanner) or a string that matches the value of
one of those constants.</td></tr>
<tr><th><em>Value Type</em></th><td> XMLCh* </td></tr>
Boris Kolpackov
committed
<tr><th><em>note: </em></th><td> See <jump href="program-others-&XercesC3Series;.html#UseSpecificScanner">Use Specific Scanner</jump>
for more programming details. </td></tr>
</table>
<p/>
<table>
<tr><th colspan="2"><em>void useImplementation(const XMLCh* const)</em></th></tr>
<tr><th><em>Description</em></th><td>This property allows the user to specify a set of features
which the parser will then use to acquire an implementation from which it will create
the DOMDocument to use when reading in an XML file.</td></tr>
<tr><th><em>Value Type</em></th><td> XMLCh* </td></tr>
</table>
<p/>
<table>
<tr><th
colspan="2"><em>setSecurityManager(Security Manager * const)</em></th></tr>
<tr><th><em>Description</em></th>
Boris Kolpackov
committed
<td>
Certain valid XML and XML Schema constructs can force a
processor to consume more system resources than an
application may wish. In fact, certain features could
be exploited by malicious document writers to produce a
denial-of-service attack. This property allows
applications to impose limits on the amount of
resources the processor will consume while processing
Boris Kolpackov
committed
these constructs.
</td></tr>
<tr><th><em>Value</em></th>
Boris Kolpackov
committed
<td>
An instance of the SecurityManager class (see
<code>xercesc/util/SecurityManager</code>). This
class's documentation describes the particular limits
that may be set. Note that, when instantiated, default
values for limits that should be appropriate in most
settings are provided. The default implementation is
not thread-safe; if thread-safety is required, the
application should extend this class, overriding
methods appropriately. The parser will not adopt the
SecurityManager instance; the application is
responsible for deleting it when it is finished with
it. If no SecurityManager instance has been provided to
the parser (the default) then processing strictly
conforming to the relevant specifications will be
performed.
</td></tr>
<tr><th><em>Value Type</em></th><td> SecurityManager* </td></tr>
</table>
<p/>
Boris Kolpackov
committed
<table>
<tr><th
colspan="2"><em>setLowWaterMark(XMLSize_t)</em></th></tr>
<tr><th><em>Description</em></th>
<td>
If the number of available bytes in the raw buffer is less than
the low water mark the parser will attempt to read more data before
continuing parsing. By default the value for this parameter is 100
bytes. You may want to set this parameter to 0 if you would like
the parser to parse the available data immediately without
potentially blocking while waiting for more date.
</td></tr>
<tr><th><em>Value</em></th>
<td>
New low water mark.
</td></tr>
<tr><th><em>Value Type</em></th><td> XMLSize_t </td></tr>
</table>
<p/>
<anchor name="DOMLSParser"/>
<s2 title="DOMLSParser">
<anchor name="ConstructDOMLSParser"/>
<s3 title="Constructing a DOMLSParser">
<p>DOMLSParser is a new interface introduced by the
<jump href="http://www.w3.org/TR/2004/REC-DOM-Level-3-LS-20040407/">
W3C DOM Level 3.0 Load and Save Specification</jump>.
DOMLSParser provides the "Load" interface for parsing XML documents and building the
corresponding DOM document tree from various input sources.
</p>
<p>A DOMLSParser instance is obtained from the DOMImplementationLS interface by invoking
its createLSParser method. For example:
</p>
<source>
#include <xercesc/dom/DOM.hpp>
#include <xercesc/util/XMLString.hpp>
#include <xercesc/util/PlatformUtils.hpp>
Boris Kolpackov
committed
using namespace std;
using namespace xercesc;
Boris Kolpackov
committed
int main (int argc, char* args[]) {
try {
XMLPlatformUtils::Initialize();
}
catch (const XMLException& toCatch) {
char* message = XMLString::transcode(toCatch.getMessage());
cout << "Error during initialization! :\n"
<< message << "\n";
return 1;
}
XMLCh tempStr[100];
XMLString::transcode("LS", tempStr, 99);
DOMImplementation *impl = DOMImplementationRegistry::getDOMImplementation(tempStr);
DOMLSParser* parser = ((DOMImplementationLS*)impl)->createLSParser(DOMImplementationLS::MODE_SYNCHRONOUS, 0);
// optionally you can set some features on this builder
if (parser->getDomConfig()->canSetParameter(XMLUni::fgDOMValidate, true))
parser->getDomConfig()->setParameter(XMLUni::fgDOMValidate, true);
if (parser->getDomConfig()->canSetParameter(XMLUni::fgDOMNamespaces, true))
parser->getDomConfig()->setParameter(XMLUni::fgDOMNamespaces, true);
if (parser->getDomConfig()->canSetParameter(XMLUni::fgDOMDatatypeNormalization, true))
parser->getDomConfig()->setParameter(XMLUni::fgDOMDatatypeNormalization, true);
// optionally you can implement your DOMErrorHandler (e.g. MyDOMErrorHandler)
// and set it to the builder
MyDOMErrorHandler* errHandler = new myDOMErrorHandler();
parser->getDomConfig()->setParameter(XMLUni::fgDOMErrorHandler, errHandler);
}
catch (const XMLException& toCatch) {
char* message = XMLString::transcode(toCatch.getMessage());
cout << "Exception message is: \n"
<< message << "\n";
return -1;
}
catch (const DOMException& toCatch) {
char* message = XMLString::transcode(toCatch.msg);
cout << "Exception message is: \n"
<< message << "\n";
return -1;
}
catch (...) {
cout << "Unexpected Exception \n" ;
return -1;
}
parser->release();
Boris Kolpackov
committed
<p>Please refer to the <jump href="api-&XercesC3Series;.html">API Documentation</jump> and the sample
DOMCount for more detail.
</p>
</s3>
<anchor name="InputSourceWrapper"/>
Alberto Massari
committed
<s3 title="How to interchange DOMLSInput and SAX InputSource?">
<p>DOM L3 has introduced a DOMLSInput which is similar to the SAX InputSource. The &XercesCName; internals
(XMLScanner, Reader, etc.) use the SAX InputSource to process the xml data. In order to support DOM L3, we need
Alberto Massari
committed
to provide a mechanism to allow the &XercesCName; internals to talk to a DOMLSInput object. Similarly, &XercesCName;
provides some framework classes for specialized types of input source (i.e. LocalFileInputSource, etc.) that are
Alberto Massari
committed
derived from the SAX InputSource. In DOM L3, to allow users implementing their own DOMLSResourceResolver(s), which return
a DOMLSInput, to utilize these framework classes, we need to provide a mechanism to map a SAX InputSource to a
DOMLSInput. Two wrapper classes are available to interchange DOMLSInput and SAX InputSource:
Alberto Massari
committed
<s4 title="Wrapper4DOMLSInput">
Alberto Massari
committed
Wraps a DOMLSInput object to a SAX InputSource.
Alberto Massari
committed
#include <xercesc/dom/DOMLSInput.hpp>
#include <xercesc/framework/Wrapper4DOMLSInput.hpp>
Alberto Massari
committed
class DBInputSource: public DOMLSInput
Alberto Massari
committed
DOMLSInput *domIS = new DBInputSource;
Wrapper4DOMLSInput domISWrapper(domIS);
XercesDOMParser parser;
parser.parse(domISWrapper);
</source>
</s4>
<s4 title="Wrapper4InputSource">
<p>
Alberto Massari
committed
Wraps a SAX InputSource object to a DOMLSInput.
#include <xercesc/framework/Wrapper4InputSource.hpp>
#include <xercesc/framework/LocalFileInputSource.hpp>
Alberto Massari
committed
DOMLSInput* MyEntityResolver::resolveResource( const XMLCh* const resourceType
, const XMLCh* const namespaceUri
, const XMLCh* const publicId
, const XMLCh* const systemId
, const XMLCh* const baseURI)
{
return new Wrapper4InputSource(new LocalFileInputSource(baseURI, systemId));
}
</source>
</s4>
Boris Kolpackov
committed
<p>Please refer to the <jump href="api-&XercesC3Series;.html">API Documentation</jump> for more detail.
<anchor name="DOMLSParserFeatures"/>
<s3 title="DOMLSParser Supported Features">
<p>The behavior of the DOMLSParser is dependent on the values of the following features.
All of the features below can be set using the function <code>DOMLSParser::getDomConfig()->setParameter(cons XMLCh* , bool)</code>.
And can be queried using the function <code>bool DOMLSParser::getDomConfig()->getParameter(const XMLCh* const)</code>.
User can also call <code>DOMLSParser::getDomConfig()->canSetParameter(const XMLCh* , bool)</code>
to query whether setting a feature to a specific value is supported
</p>
<s4 title="DOM Features">
<table>
<tr><th colspan="2"><em>cdata-sections</em></th></tr>
<tr><th><em>true:</em></th><td> Keep CDATASection nodes in the document. </td></tr>
<tr><th><em>false:</em></th><td> Not Supported. </td></tr>
<tr><th><em>default:</em></th><td> true </td></tr>
<tr><th><em>XMLUni Predefined Constant:</em></th><td> fgDOMCDATASections </td></tr>
<tr><th><em>note:</em></th><td> Setting this feature to false is not supported. </td></tr>
<tr><th><em>see:</em></th><td>
Alberto Massari
committed
<jump href="http://www.w3.org/TR/2004/REC-DOM-Level-3-LS-20040407">
DOM Level 3.0 Load and Save Specification</jump>