diff --git a/doc/apidocs.xml b/doc/apidocs.xml index 0a9f97ef46ad56665ce5d3075baaf0e5c668fe71..e0d1d3e67556eb10490c11cfae863d1ad2c26edc 100644 --- a/doc/apidocs.xml +++ b/doc/apidocs.xml @@ -23,8 +23,8 @@ <jump href="http://www.w3.org/TR/2002/WD-DOM-Level-3-Core-20020409/"> DOM Level 3.0 Core Specification</jump>, and <jump href="http://www.w3.org/TR/2002/WD-DOM-Level-3-ASLS-20020409/"> - DOM Level 3.0 Load and Save Specification</jump> (W3C Working Draft of 09 April 2002). - This implementation is experimental. + DOM Level 3.0 Abstract Schemas and Load and Save Specification</jump> + (W3C Working Draft of 09 April 2002). This implementation is experimental. See <jump href="dom3.html">DOM Level 3 Support</jump> for details.</li> </ul> diff --git a/doc/dom3.xml b/doc/dom3.xml index 9cfcfe046c25d88190fc573a74d3049cb2173465..e9e8f9c8970aa2ea9943cb16f8522c8036e6ed4e 100644 --- a/doc/dom3.xml +++ b/doc/dom3.xml @@ -19,7 +19,8 @@ <li><jump href="http://www.w3.org/TR/2002/WD-DOM-Level-3-Core-20020409/"> DOM Level 3.0 Core Specification</jump>, a W3C Working Draft of 09 April 2002 and</li> <li><jump href="http://www.w3.org/TR/2002/WD-DOM-Level-3-ASLS-20020409/"> - DOM Level 3.0 Load and Save Specification</jump>, a W3C Working Draft of 09 April 2002.</li> + DOM Level 3.0 Abstract Schemas and Load and Save Specification</jump>, + a W3C Working Draft of 09 April 2002.</li> </ul> </s2> diff --git a/doc/program-deprecateddom.xml b/doc/program-deprecateddom.xml index 2bde2cdb9d639552c4abbe2965b249c798a496cf..90add8f93aad64e12de0e09255a2d10811ee7bad 100644 --- a/doc/program-deprecateddom.xml +++ b/doc/program-deprecateddom.xml @@ -20,6 +20,246 @@ </p> </s2> + <s2 title="Using this set of deprecated API"> + <s3 title="Accessing API from application code"> + + <source> + // C++ + #include <xercesc/dom/deprecated/DOM.hpp></source> + + <source>// Compared to Java + import org.w3c.dom.*</source> + + <p>The header file <dom/deprecated/DOM.hpp> includes all the + individual headers for this set of deprecated DOM API classes. </p> + </s3> + + <s3 title="Class Names"> + <p>The C++ class names are prefixed with "DOM_". 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> + + <p>The use of C++ namespaces would also have solved this + conflict problem, but for the fact that many compilers do not + yet support them.</p> + + <source>DOM_Document myDocument; // C++ + DOM_Node aNode; + DOM_Text someText;</source> + + <source>Document myDocument; // Compared to Java + Node aNode; + Text someText;</source> + + <p>If you wish to use the Java class names in C++, then you need + to typedef them in C++. This is not advisable for the general + case - conflicts really do occur - but can be very useful when + converting a body of existing Java code to C++.</p> + + <source>typedef DOM_Document Document; + typedef DOM_Node Node; + + Document myDocument; // Now C++ usage is + // indistinguishable from Java + Node aNode;</source> + </s3> + + + <s3 title="Objects and Memory Management"> + <p>This deprecated C++ DOM implementation uses automatic memory management, + implemented using reference counting. As a result, the C++ + code for most DOM operations is very similar to the equivalent + Java code, right down to the use of factory methods in the DOM + document class for nearly all object creation, and the lack of + any explicit object deletion.</p> + + <p>Consider the following code snippets </p> + + <source>// This is C++ + DOM_Node aNode; + aNode = someDocument.createElement("ElementName"); + DOM_Node docRootNode = someDoc.getDocumentElement(); + docRootNode.AppendChild(aNode);</source> + + <source>// This is Java + Node aNode; + aNode = someDocument.createElement("ElementName"); + Node docRootNode = someDoc.getDocumentElement(); + docRootNode.AppendChild(aNode);</source> + + <p>The Java and the C++ are identical on the surface, except for + the class names, and this similarity remains true for most DOM + code. </p> + + <p>However, Java and C++ handle objects in somewhat different + ways, making it important to understand a little bit of what + is going on beneath the surface.</p> + + <p>In Java, the variable <code>aNode</code> is an object reference , + essentially a pointer. It is initially == null, and references + an object only after the assignment statement in the second + line of the code.</p> + + <p>In C++ the variable <code>aNode</code> is, from the C++ language's + perspective, an actual live object. It is constructed when the + first line of the code executes, and DOM_Node::operator = () + executes at the second line. The C++ class DOM_Node + essentially a form of a smart-pointer; it implements much of + the behavior of a Java Object Reference variable, and + delegates the DOM behaviors to an implementation class that + lives behind the scenes. </p> + + <p>Key points to remember when using the C++ DOM classes:</p> + + <ul> + <li>Create them as local variables, or as member variables of + some other class. Never "new" a DOM object into the heap or + make an ordinary C pointer variable to one, as this will + greatly confuse the automatic memory management. </li> + + <li>The "real" DOM objects - nodes, attributes, CData + sections, whatever, do live on the heap, are created with the + create... methods on class DOM_Document. DOM_Node and the + other DOM classes serve as reference variables to the + underlying heap objects.</li> + + <li>The visible DOM classes may be freely copied (assigned), + passed as parameters to functions, or returned by value from + functions.</li> + + <li>Memory management of the underlying DOM heap objects is + automatic, implemented by means of reference counting. So long + as some part of a document can be reached, directly or + indirectly, via reference variables that are still alive in + the application program, the corresponding document data will + stay alive in the heap. When all possible paths of access have + been closed off (all of the application's DOM objects have + gone out of scope) the heap data itself will be automatically + deleted. </li> + + <li>There are restrictions on the ability to subclass the DOM + classes. </li> + + </ul> + + </s3> + + <s3 title="String Type - DOMString"> + <p>Class DOMString provides the mechanism for passing string + data to and from the DOM API. DOMString is not intended to be + a completely general string class, but rather to meet the + specific needs of the DOM API.</p> + + <p>The design derives from two primary sources: from the DOM's + CharacterData interface and from class <code>java.lang.string</code>.</p> + + <p>Main features are:</p> + + <ul> + <li>It stores Unicode text.</li> + + <li>Automatic memory management, using reference counting.</li> + + <li>DOMStrings are mutable - characters can be inserted, + deleted or appended.</li> + + </ul> + <p></p> + + <p>When a string is passed into a method of the DOM, when + setting the value of a Node, for example, the string is cloned + so that any subsequent alteration or reuse of the string by + the application will not alter the document contents. + Similarly, when strings from the document are returned to an + application via the DOM API, the string is cloned so that the + document can not be inadvertently altered by subsequent edits + to the string.</p> + + <note>The ICU classes are a more general solution to UNICODE + character handling for C++ applications. ICU is an Open + Source Unicode library, available at the <jump + href="http://oss.software.ibm.com/icu/">IBM + DeveloperWorks website</jump>.</note> + + </s3> + + <s3 title="Equality Testing"> + <p>The DOMString equality operators (and all of the rest of the + DOM class conventions) are modeled after the Java + equivalents. The equals() method compares the content of the + string, while the == operator checks whether the string + reference variables (the application program variables) refer + to the same underlying string in memory. This is also true of + DOM_Node, DOM_Element, etc., in that operator == tells whether + the variables in the application are referring to the same + actual node or not. It's all very Java-like </p> + + <ul> + <li>bool operator == () is true if the DOMString variables + refer to the same underlying storage. </li> + + <li>bool equals() is true if the strings contain the same + characters. </li> + + </ul> + <p>Here is an example of how the equality operators work: </p> + <source>DOMString a = "Hello"; + DOMString b = a; + DOMString c = a.clone(); + if (b == a) // This is true + if (a == c) // This is false + if (a.equals(c)) // This is true + b = b + " World"; + if (b == a) // Still true, and the string's + // value is "Hello World" + if (a.equals(c)) // false. a is "Hello World"; + // c is still "Hello".</source> + </s3> + + <s3 title="Downcasting"> + <p>Application code sometimes must cast an object reference from + DOM_Node to one of the classes deriving from DOM_Node, + DOM_Element, for example. The syntax for doing this in C++ is + different from that in Java.</p> + + <source>// This is C++ + DOM_Node aNode = someFunctionReturningNode(); + DOM_Element el = (DOM_Element &) aNode;</source> + + <source>// This is Java + Node aNode = someFunctionReturningNode(); + Element el = (Element) aNode;</source> + + <p>The C++ cast is not type-safe; the Java cast is checked for + compatible types at runtime. If necessary, a type-check can + be made in C++ using the node type information: </p> + + <source>// This is C++ + + DOM_Node aNode = someFunctionReturningNode(); + DOM_Element el; // by default, el will == null. + + if (anode.getNodeType() == DOM_Node::ELEMENT_NODE) + el = (DOM_Element &) aNode; + else + // aNode does not refer to an element. + // Do something to recover here.</source> + + </s3> + + <s3 title="Subclassing"> + <p>The C++ DOM classes, DOM_Node, DOM_Attr, DOM_Document, etc., + are not designed to be subclassed by an application + program. </p> + + <p>As an alternative, the DOM_Node class provides a User Data + field for use by applications as a hook for extending nodes by + referencing additional data or objects. See the API + description for DOM_Node for details.</p> + </s3> + </s2> + <s2 title="Constructing a DOMParser"> <p>In order to use &XercesCName; to parse XML files using the deprecated DOM, you will need to create an instance of the DOMParser class. The example @@ -80,243 +320,4 @@ int main (int argc, char* args[]) { </source> </s2> - <s2 title="Accessing this set of deprecated API"> - -<source> -// C++ -#include <xercesc/dom/deprecated/DOM.hpp></source> - -<source>// Compared to Java -import org.w3c.dom.*</source> - - <p>The header file <dom/deprecated/DOM.hpp> includes all the - individual headers for this set of deprecated DOM API classes. </p> - - </s2> - - <s2 title="Class Names"> - <p>The C++ class names are prefixed with "DOM_". 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> - - <p>The use of C++ namespaces would also have solved this - conflict problem, but for the fact that many compilers do not - yet support them.</p> - -<source>DOM_Document myDocument; // C++ -DOM_Node aNode; -DOM_Text someText;</source> - -<source>Document myDocument; // Compared to Java -Node aNode; -Text someText;</source> - - <p>If you wish to use the Java class names in C++, then you need - to typedef them in C++. This is not advisable for the general - case - conflicts really do occur - but can be very useful when - converting a body of existing Java code to C++.</p> - -<source>typedef DOM_Document Document; -typedef DOM_Node Node; - -Document myDocument; // Now C++ usage is - // indistinguishable from Java -Node aNode;</source> - </s2> - - - <s2 title="Objects and Memory Management"> - <p>This deprecated C++ DOM implementation uses automatic memory management, - implemented using reference counting. As a result, the C++ - code for most DOM operations is very similar to the equivalent - Java code, right down to the use of factory methods in the DOM - document class for nearly all object creation, and the lack of - any explicit object deletion.</p> - - <p>Consider the following code snippets </p> - -<source>// This is C++ -DOM_Node aNode; -aNode = someDocument.createElement("ElementName"); -DOM_Node docRootNode = someDoc.getDocumentElement(); -docRootNode.AppendChild(aNode);</source> - -<source>// This is Java -Node aNode; -aNode = someDocument.createElement("ElementName"); -Node docRootNode = someDoc.getDocumentElement(); -docRootNode.AppendChild(aNode);</source> - - <p>The Java and the C++ are identical on the surface, except for - the class names, and this similarity remains true for most DOM - code. </p> - - <p>However, Java and C++ handle objects in somewhat different - ways, making it important to understand a little bit of what - is going on beneath the surface.</p> - - <p>In Java, the variable <code>aNode</code> is an object reference , - essentially a pointer. It is initially == null, and references - an object only after the assignment statement in the second - line of the code.</p> - - <p>In C++ the variable <code>aNode</code> is, from the C++ language's - perspective, an actual live object. It is constructed when the - first line of the code executes, and DOM_Node::operator = () - executes at the second line. The C++ class DOM_Node - essentially a form of a smart-pointer; it implements much of - the behavior of a Java Object Reference variable, and - delegates the DOM behaviors to an implementation class that - lives behind the scenes. </p> - - <p>Key points to remember when using the C++ DOM classes:</p> - - <ul> - <li>Create them as local variables, or as member variables of - some other class. Never "new" a DOM object into the heap or - make an ordinary C pointer variable to one, as this will - greatly confuse the automatic memory management. </li> - - <li>The "real" DOM objects - nodes, attributes, CData - sections, whatever, do live on the heap, are created with the - create... methods on class DOM_Document. DOM_Node and the - other DOM classes serve as reference variables to the - underlying heap objects.</li> - - <li>The visible DOM classes may be freely copied (assigned), - passed as parameters to functions, or returned by value from - functions.</li> - - <li>Memory management of the underlying DOM heap objects is - automatic, implemented by means of reference counting. So long - as some part of a document can be reached, directly or - indirectly, via reference variables that are still alive in - the application program, the corresponding document data will - stay alive in the heap. When all possible paths of access have - been closed off (all of the application's DOM objects have - gone out of scope) the heap data itself will be automatically - deleted. </li> - - <li>There are restrictions on the ability to subclass the DOM - classes. </li> - - </ul> - - </s2> - - <s2 title="DOMString"> - <p>Class DOMString provides the mechanism for passing string - data to and from the DOM API. DOMString is not intended to be - a completely general string class, but rather to meet the - specific needs of the DOM API.</p> - - <p>The design derives from two primary sources: from the DOM's - CharacterData interface and from class <code>java.lang.string</code>.</p> - - <p>Main features are:</p> - - <ul> - <li>It stores Unicode text.</li> - - <li>Automatic memory management, using reference counting.</li> - - <li>DOMStrings are mutable - characters can be inserted, - deleted or appended.</li> - - </ul> - <p></p> - - <p>When a string is passed into a method of the DOM, when - setting the value of a Node, for example, the string is cloned - so that any subsequent alteration or reuse of the string by - the application will not alter the document contents. - Similarly, when strings from the document are returned to an - application via the DOM API, the string is cloned so that the - document can not be inadvertently altered by subsequent edits - to the string.</p> - - <note>The ICU classes are a more general solution to UNICODE - character handling for C++ applications. ICU is an Open - Source Unicode library, available at the <jump - href="http://oss.software.ibm.com/icu/">IBM - DeveloperWorks website</jump>.</note> - - </s2> - - <s2 title="Equality Testing"> - <p>The DOMString equality operators (and all of the rest of the - DOM class conventions) are modeled after the Java - equivalents. The equals() method compares the content of the - string, while the == operator checks whether the string - reference variables (the application program variables) refer - to the same underlying string in memory. This is also true of - DOM_Node, DOM_Element, etc., in that operator == tells whether - the variables in the application are referring to the same - actual node or not. It's all very Java-like </p> - - <ul> - <li>bool operator == () is true if the DOMString variables - refer to the same underlying storage. </li> - - <li>bool equals() is true if the strings contain the same - characters. </li> - - </ul> - <p>Here is an example of how the equality operators work: </p> -<source>DOMString a = "Hello"; -DOMString b = a; -DOMString c = a.clone(); -if (b == a) // This is true -if (a == c) // This is false -if (a.equals(c)) // This is true -b = b + " World"; -if (b == a) // Still true, and the string's - // value is "Hello World" -if (a.equals(c)) // false. a is "Hello World"; - // c is still "Hello".</source> - </s2> - - <s2 title="Downcasting"> - <p>Application code sometimes must cast an object reference from - DOM_Node to one of the classes deriving from DOM_Node, - DOM_Element, for example. The syntax for doing this in C++ is - different from that in Java.</p> - -<source>// This is C++ -DOM_Node aNode = someFunctionReturningNode(); -DOM_Element el = (DOM_Element &) aNode;</source> - -<source>// This is Java -Node aNode = someFunctionReturningNode(); -Element el = (Element) aNode;</source> - - <p>The C++ cast is not type-safe; the Java cast is checked for - compatible types at runtime. If necessary, a type-check can - be made in C++ using the node type information: </p> - -<source>// This is C++ - -DOM_Node aNode = someFunctionReturningNode(); -DOM_Element el; // by default, el will == null. - -if (anode.getNodeType() == DOM_Node::ELEMENT_NODE) - el = (DOM_Element &) aNode; -else - // aNode does not refer to an element. - // Do something to recover here.</source> - - </s2> - - <s2 title="Subclassing"> - <p>The C++ DOM classes, DOM_Node, DOM_Attr, DOM_Document, etc., - are not designed to be subclassed by an application - program. </p> - - <p>As an alternative, the DOM_Node class provides a User Data - field for use by applications as a hook for extending nodes by - referencing additional data or objects. See the API - description for DOM_Node for details.</p> - </s2> - </s1> diff --git a/doc/program-dom.xml b/doc/program-dom.xml index b161e6ee40df34bea8d05b96be96f787fca9b047..c160c460c34489216b8cbec4081f47d1435c9941 100644 --- a/doc/program-dom.xml +++ b/doc/program-dom.xml @@ -16,67 +16,12 @@ </ul> </s2> - <anchor name="ConstructXercesDOMParser"/> - <s2 title="Constructing a XercesDOMParser"> - <p>In order to use &XercesCName; to parse XML files using DOM, you - will need to 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> - -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"; - delete [] message; - return 1; - } - - char* xmlFile = "x1.xml"; - XercesDOMParser* parser = new XercesDOMParser(); - parser->setValidationScheme(XercesDOMParser::Val_Always); // optional. - parser->setDoNamespaces(true); // optional - - ErrorHandler* errHandler = (ErrorHandler*) new HandlerBase(); - parser->setErrorHandler(errHandler); - - try { - parser->parse(xmlFile); - } - catch (const XMLException& toCatch) { - char* message = XMLString::transcode(toCatch.getMessage()); - cout << "Exception message is: \n" - << message << "\n"; - delete [] message; - return -1; - } - catch (const DOMException& toCatch) { - char* message = XMLString::transcode(toCatch.getMessage()); - cout << "Exception message is: \n" - << message << "\n"; - delete [] message; - return -1; - } - catch (...) { - cout << "Unexpected Exception \n" ; - return -1; - } - - delete parser; - delete errHandler; - return 0; -} - </source> + <anchor name="DOM3"/> + <s2 title="DOM Level 3 Support in &XercesCName;"> + <p>The &XercesCName; &XercesCVersion; contains a partial implementation of the W3C + Document Object Model Level 3. This implementation is experimental. See the document + <jump href="dom3.html"> DOM Level 3 Support</jump> for details. + </p> </s2> <anchor name="UsingDOMAPI"/> @@ -95,7 +40,7 @@ int main (int argc, char* args[]) { <anchor name="DOMClassNames"/> <s3 title="Class Names"> <p> - The DOM class names are prefixed with "DOM", e.g. "DOMNode". The intent is + 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> @@ -194,11 +139,233 @@ int main (int argc, char* args[]) { </s3> </s2> - <anchor name="DOM3"/> - <s2 title="DOM Level 3 Support in &XercesCName;"> - <p>The &XercesCName; &XercesCVersion; contains a partial implementation of the W3C - Document Object Model Level 3. This implementation is experimental. See the document - <jump href="dom3.html"> DOM Level 3 Support</jump> for details. + + <anchor name="ConstructXercesDOMParser"/> + <s2 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> + +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"; + delete [] message; + return 1; + } + + XercesDOMParser* parser = new XercesDOMParser(); + parser->setValidationScheme(XercesDOMParser::Val_Always); // optional. + 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"; + delete [] message; + return -1; + } + catch (const DOMException& toCatch) { + char* message = XMLString::transcode(toCatch.getMessage()); + cout << "Exception message is: \n" + << message << "\n"; + delete [] message; + return -1; + } + catch (...) { + cout << "Unexpected Exception \n" ; + return -1; + } + + delete parser; + delete errHandler; + return 0; +} + </source> + </s2> + + <anchor name="ConstructDOMBuilder"/> + <s2 title="Constructing a DOMBuilder"> + <p>DOMBuilder is a new interface introduced by the + <jump href="http://www.w3.org/TR/2002/WD-DOM-Level-3-ASLS-20020409/"> + W3C DOM Level 3.0 Abstract Schemas and Load and Save Specification</jump>. + DOMBuilder provides the "Load" interface for parsing XML documents and building the + corresponding DOM document tree from various input sources. + </p> + <p>A DOMBuilder instance is obtained from the DOMImplementationLS interface by invoking + its createDOMBuilder method. For example: + </p> +<source> +#include <xercesc/dom/DOM.hpp> +#include <xercesc/util/XMLString.hpp> + +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"; + delete [] message; + return 1; + } + + + XMLCh tempStr[100]; + XMLString::transcode("LS", tempStr, 99); + DOMImplementation *impl = DOMImplementationRegistry::getDOMImplementation(tempStr); + DOMBuilder* parser = ((DOMImplementationLS*)impl)->createDOMBuilder(); + + // optionally you can set some features on this builder + if (parser->canSetFeature(XMLUni::fgDOMValidation, true) + parser->setFeature(XMLUni::fgDOMValidation, true); + if (parser->canSetFeature(XMLUni::fgDOMNamespaces, true) + parser->setFeature(XMLUni::fgDOMNamespaces, true); + + + // optionally you can implement your DOMErrorHandler (e.g. MyDOMErrorHandler) + // and set it to the builder + MyDOMErrorHandler* errHandler = new myDOMErrorHandler(); + parser->setErrorHandler(errHandler); + + char* xmlFile = "x1.xml"; + + try { + parser->parseURI(xmlFile); + } + catch (const XMLException& toCatch) { + char* message = XMLString::transcode(toCatch.getMessage()); + cout << "Exception message is: \n" + << message << "\n"; + delete [] message; + return -1; + } + catch (const DOMException& toCatch) { + char* message = XMLString::transcode(toCatch.getMessage()); + cout << "Exception message is: \n" + << message << "\n"; + delete [] message; + return -1; + } + catch (...) { + cout << "Unexpected Exception \n" ; + return -1; + } + + delete parser; + delete errHandler; + return 0; +} +</source> + <p>Please refer to the <jump href="api.html">API Documentataion</jump> and the sample + DOMCount for more detail. + </p> + </s2> + + <anchor name="InputSourceWrapper"/> + <s2 title="How to interchange DOMInputSource and SAX InputSource?"> + <p>...</p> + </s2> + + <anchor name="ConstructDOMWriter"/> + <s2 title="Constructing a DOMWriter"> + <p>DOMWriter is a new interface introduced by the + <jump href="http://www.w3.org/TR/2002/WD-DOM-Level-3-ASLS-20020409/"> + W3C DOM Level 3.0 Abstract Schemas and Load and Save Specification</jump>. + DOMWriter provides the "Save" interface for serializing (writing) a DOM document into + XML data. The XML data can be written to various type of output stream. + </p> + <p>A DOMWriter instance is obtained from the DOMImplementationLS interface by invoking + its createDOMWriter method. For example: + </p> +<source> +#include <xercesc/dom/DOM.hpp> +#include <xercesc/util/XMLString.hpp> + +int serializeDOM(DOMNode* node) { + + XMLCh tempStr[100]; + XMLString::transcode("LS", tempStr, 99); + DOMImplementation *impl = DOMImplementationRegistry::getDOMImplementation(tempStr); + DOMWriter* theSerializer = ((DOMImplementationLS*)impl)->createDOMWriter(); + + // optionally you can set some features on this serializer + if (theSerializer->canSetFeature(XMLUni::fgDOMWRTDiscardDefaultContent, true)) + theSerializer->setFeature(XMLUni::fgDOMWRTDiscardDefaultContent, true); + + if (theSerializer->canSetFeature(XMLUni::fgDOMWRTFormatPrettyPrint, true)) + theSerializer->setFeature(XMLUni::fgDOMWRTFormatPrettyPrint, true); + + // optionally you can implement your DOMWriterFilter (e.g. MyDOMWriterFilter) + // and set it to the serializer + MyDOMWriterFilter* myFilter = new myDOMWriterFilter(); + theSerializer->setFilter(myFilter); + + // optionally you can implement your DOMErrorHandler (e.g. MyDOMErrorHandler) + // and set it to the serializer + MyDOMErrorHandler* errHandler = new myDOMErrorHandler(); + theSerializer->setErrorHandler(myErrorHandler); + + // StdOutFormatTarget prints the resultant XML stream + // to stdout once it receives any thing from the serializer. + StdOutFormatTarget *myFormTarget = new StdOutFormatTarget(); + + try { + // do the serialization through DOMWriter::writeNode(); + theSerializer->writeNode(myFormTarget, *node); + } + catch (const XMLException& toCatch) { + char* message = XMLString::transcode(toCatch.getMessage()); + cout << "Exception message is: \n" + << message << "\n"; + delete [] message; + return -1; + } + catch (const DOMException& toCatch) { + char* message = XMLString::transcode(toCatch.getMessage()); + cout << "Exception message is: \n" + << message << "\n"; + delete [] message; + return -1; + } + catch (...) { + cout << "Unexpected Exception \n" ; + return -1; + } + + + delete theSerializer; + delete myErrorHandler; + delete myFilter; + delete myFormTarget; + return 0; +} + +</source> + <p>Please refer to the <jump href="api.html">API Documentataion</jump> and the sample + DOMPrint for more detail. </p> </s2> diff --git a/doc/program-sax.xml b/doc/program-sax.xml index 55e296dd104fd42730114fe51e63793221e54754..ad6f368b204462aadb6476c9fd28d1940874b7fa 100644 --- a/doc/program-sax.xml +++ b/doc/program-sax.xml @@ -4,70 +4,6 @@ <s1 title="SAX1 Programming Guide"> <anchor name="ConstructParser"/> - <s2 title="Constructing a SAXParser"> - <p>In order to use &XercesCName; to parse XML files, you will - need to create an instance of the SAXParser class. The example - below shows the code you need in order to create an instance - of SAXParser. The DocumentHandler and ErrorHandler instances - required by the SAX API are provided using the HandlerBase - class supplied with &XercesCName;.</p> - -<source> -#include <xercesc/parsers/SAXParser.hpp> -#include <xercesc/sax/HandlerBase.hpp> -#include <xercesc/util/XMLString.hpp> - -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"; - delete [] message; - return 1; - } - - char* xmlFile = "x1.xml"; - SAXParser* parser = new SAXParser(); - parser->setDoValidation(true); // optional. - parser->setDoNamespaces(true); // optional - - DocumentHandler* docHandler = new HandlerBase(); - ErrorHandler* errHandler = (ErrorHandler*) docHandler; - parser->setDocumentHandler(docHandler); - parser->setErrorHandler(errHandler); - - try { - parser->parse(xmlFile); - } - catch (const XMLException& toCatch) { - char* message = XMLString::transcode(toCatch.getMessage()); - cout << "Exception message is: \n" - << message << "\n"; - delete [] message; - return -1; - } - catch (const SAXParseException& toCatch) { - char* message = XMLString::transcode(toCatch.getMessage()); - cout << "Exception message is: \n" - << message << "\n"; - delete [] message; - return -1; - } - catch (...) { - cout << "Unexpected Exception \n" ; - return -1; - } - - delete parser; - delete docHandler; - return 0; -}</source> - </s2> - <anchor name="UsingSAX1API"/> <s2 title="Using the SAX API"> <p>The SAX API for XML parsers was originally developed for @@ -139,4 +75,68 @@ MySAXHandler::fatalError(const SAXParseException& exception) the sample applications.</p> </s2> + <s2 title="Constructing a SAXParser"> + <p>In order to use &XercesCName; to parse XML files, you will + need to create an instance of the SAXParser class. The example + below shows the code you need in order to create an instance + of SAXParser. The DocumentHandler and ErrorHandler instances + required by the SAX API are provided using the HandlerBase + class supplied with &XercesCName;.</p> + +<source> +#include <xercesc/parsers/SAXParser.hpp> +#include <xercesc/sax/HandlerBase.hpp> +#include <xercesc/util/XMLString.hpp> + +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"; + delete [] message; + return 1; + } + + char* xmlFile = "x1.xml"; + SAXParser* parser = new SAXParser(); + parser->setDoValidation(true); // optional. + parser->setDoNamespaces(true); // optional + + DocumentHandler* docHandler = new HandlerBase(); + ErrorHandler* errHandler = (ErrorHandler*) docHandler; + parser->setDocumentHandler(docHandler); + parser->setErrorHandler(errHandler); + + try { + parser->parse(xmlFile); + } + catch (const XMLException& toCatch) { + char* message = XMLString::transcode(toCatch.getMessage()); + cout << "Exception message is: \n" + << message << "\n"; + delete [] message; + return -1; + } + catch (const SAXParseException& toCatch) { + char* message = XMLString::transcode(toCatch.getMessage()); + cout << "Exception message is: \n" + << message << "\n"; + delete [] message; + return -1; + } + catch (...) { + cout << "Unexpected Exception \n" ; + return -1; + } + + delete parser; + delete docHandler; + return 0; +}</source> + </s2> + </s1> diff --git a/doc/program-sax2.xml b/doc/program-sax2.xml index 5f9359ac8cf4fd03cfb926354d62da34c8e3f980..a78487c4259272c1d092d0c6030a835525a19049 100644 --- a/doc/program-sax2.xml +++ b/doc/program-sax2.xml @@ -4,71 +4,6 @@ <s1 title="SAX2 Programming Guide"> <anchor name="ConstructParser2"/> - <s2 title="Constructing an XML Reader"> - <p>In order to use &XercesCName; to parse XML files, you will - need to create an instance of the SAX2XMLReader class. The example - below shows the code you need in order to create an instance - of SAX2XMLReader. The ContentHandler and ErrorHandler instances - required by the SAX API are provided using the DefaultHandler - class supplied with &XercesCName;.</p> - -<source> -#include <xercesc/sax2/SAX2XMLReader.hpp> -#include <xercesc/sax2/XMLReaderFactory.hpp> -#include <xercesc/sax2/DefaultHandler.hpp> -#include <xercesc/util/XMLString.hpp> - -int main (int argc, char* args[]) { - - try { - XMLPlatformUtils::Initialize(); - } - catch (const XMLException& toCatch) { - char* message = XMLString::transcode(toCatch.getMessage()); - cout << "Error during initialization! :\n" - cout << "Exception message is: \n" - << message << "\n"; - delete [] message; - return 1; - } - - char* xmlFile = "x1.xml"; - SAX2XMLReader* parser = XMLReaderFactory::createXMLReader(); - parser->setFeature(XMLUni::fgSAX2CoreValidation, true) // optional - parser->setFeature(XMLUni::fgSAX2CoreNameSpaces, true) // optional - - DefaultHandler* defaultHandler = new DefaultHandler(); - parser->setContentHandler(defaultHandler); - parser->setErrorHandler(defaultHandler); - - try { - parser->parse(xmlFile); - } - catch (const XMLException& toCatch) { - char* message = XMLString::transcode(toCatch.getMessage()); - cout << "Exception message is: \n" - << message << "\n"; - delete [] message; - return -1; - } - catch (const SAXParseException& toCatch) { - char* message = XMLString::transcode(toCatch.getMessage()); - cout << "Exception message is: \n" - << message << "\n"; - delete [] message; - return -1; - } - catch (...) { - cout << "Unexpected Exception \n" ; - return -1; - } - - delete parser; - delete defaultHandler; - return 0; -}</source> - </s2> - <anchor name="UsingSAX2API"/> <s2 title="Using the SAX2 API"> <p>The SAX2 API for XML parsers was originally developed for @@ -147,6 +82,71 @@ MySAX2Handler::fatalError(const SAXParseException& exception) the sample applications.</p> </s2> + <s2 title="Constructing an XML Reader"> + <p>In order to use &XercesCName; to parse XML files, you will + need to create an instance of the SAX2XMLReader class. The example + below shows the code you need in order to create an instance + of SAX2XMLReader. The ContentHandler and ErrorHandler instances + required by the SAX API are provided using the DefaultHandler + class supplied with &XercesCName;.</p> + +<source> +#include <xercesc/sax2/SAX2XMLReader.hpp> +#include <xercesc/sax2/XMLReaderFactory.hpp> +#include <xercesc/sax2/DefaultHandler.hpp> +#include <xercesc/util/XMLString.hpp> + +int main (int argc, char* args[]) { + + try { + XMLPlatformUtils::Initialize(); + } + catch (const XMLException& toCatch) { + char* message = XMLString::transcode(toCatch.getMessage()); + cout << "Error during initialization! :\n" + cout << "Exception message is: \n" + << message << "\n"; + delete [] message; + return 1; + } + + char* xmlFile = "x1.xml"; + SAX2XMLReader* parser = XMLReaderFactory::createXMLReader(); + parser->setFeature(XMLUni::fgSAX2CoreValidation, true) // optional + parser->setFeature(XMLUni::fgSAX2CoreNameSpaces, true) // optional + + DefaultHandler* defaultHandler = new DefaultHandler(); + parser->setContentHandler(defaultHandler); + parser->setErrorHandler(defaultHandler); + + try { + parser->parse(xmlFile); + } + catch (const XMLException& toCatch) { + char* message = XMLString::transcode(toCatch.getMessage()); + cout << "Exception message is: \n" + << message << "\n"; + delete [] message; + return -1; + } + catch (const SAXParseException& toCatch) { + char* message = XMLString::transcode(toCatch.getMessage()); + cout << "Exception message is: \n" + << message << "\n"; + delete [] message; + return -1; + } + catch (...) { + cout << "Unexpected Exception \n" ; + return -1; + } + + delete parser; + delete defaultHandler; + return 0; +}</source> + </s2> + <anchor name="SAX2Features"/> <s2 title="Xerces SAX2 Supported Features"> diff --git a/doc/program.xml b/doc/program.xml index 7274ac096ae6c5523fca081f8657973f0aa8a96a..2ad47b6cbfa0f9bf4f449fd6a81c18b9149f16de 100644 --- a/doc/program.xml +++ b/doc/program.xml @@ -10,9 +10,12 @@ or jump directly to:</p> <ul> <li><jump href="program-dom.html#Objectives">Design Objectives</jump></li> - <li><jump href="program-dom.html#ConstructXercesDOMParser">Constructing a XercesDOMParser</jump></li> - <li><jump href="program-dom.html#UsingDOMAPI">Using DOM API</jump></li> <li><jump href="program-dom.html#DOM3">DOM Level 3 Support in &XercesCName; </jump></li> + <li><jump href="program-dom.html#UsingDOMAPI">Using DOM API</jump></li> + <li><jump href="program-dom.html#ConstructXercesDOMParser">Constructing a XercesDOMParser</jump></li> + <li><jump href="program-dom.html#ConstructDOMBuilder">Constructing a DOMBuilder</jump></li> + <li><jump href="program-dom.html#InputSourceWrapper">How to interchange DOMInputSource and SAX InputSource?</jump></li> + <li><jump href="program-dom.html#ConstructDOMWriter">Constructing a DOMWriter</jump></li> <li><jump href="program-dom.html#Deprecated">Deprecated - Java-like DOM</jump></li> </ul> </s2> @@ -21,8 +24,8 @@ <p>Read the <jump href="program-sax.html">SAX Programming Guide</jump> document or jump directly to:</p> <ul> - <li><jump href="program-sax.html#ConstructParser">Constructing a SAXParser</jump></li> <li><jump href="program-sax.html#UsingSAX1API">Using the SAX API</jump></li> + <li><jump href="program-sax.html#ConstructParser">Constructing a SAXParser</jump></li> </ul> </s2> @@ -30,8 +33,8 @@ <p>Read the <jump href="program-sax2.html">SAX2 Programming Guide</jump> document or jump directly to:</p> <ul> - <li><jump href="program-sax2.html#ConstructParser2">Constructing an XML Reader</jump></li> <li><jump href="program-sax2.html#UsingSAX2API">Using the SAX2 API</jump></li> + <li><jump href="program-sax2.html#ConstructParser2">Constructing an XML Reader</jump></li> <li><jump href="program-sax2.html#SAX2Features">Supported Features</jump></li> <li><jump href="program-sax2.html#SAX2Properties">Supported Properties</jump></li> </ul> diff --git a/doc/readme.xml b/doc/readme.xml index 0c621546f4e162dbf485caf0f81dec67b3ddc3a6..cee28d0e08ffaae80c3ebaa1cf34fb47594e9a4e 100644 --- a/doc/readme.xml +++ b/doc/readme.xml @@ -61,8 +61,8 @@ <jump href="http://www.w3.org/TR/2002/WD-DOM-Level-3-Core-20020409/"> DOM Level 3.0 Core Specification</jump>, W3C Working Draft of 09 April 2002 and <jump href="http://www.w3.org/TR/2002/WD-DOM-Level-3-ASLS-20020409/"> - DOM Level 3.0 Load and Save Specification</jump>, W3C Working Draft of 09 April 2002. - This implementation is experimental. + DOM Level 3.0 Abstract Schemas and Load and Save Specification</jump>, + W3C Working Draft of 09 April 2002. This implementation is experimental. See <jump href="dom3.html">DOM Level 3 Support</jump> for details.</li> <li>Source code, samples, and documentation is provided.</li> <li>Programmatic generation and validation of XML</li>