You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by tn...@apache.org on 2002/05/21 20:22:16 UTC
cvs commit: xml-xerces/c/doc program-sax.xml program-sax2.xml
tng 02/05/21 11:22:16
Modified: c/doc program-sax.xml program-sax2.xml
Log:
Documentation Update: Update SAX Programming Guide to use XMLCh* instead of DOMString
Revision Changes Path
1.4 +26 -12 xml-xerces/c/doc/program-sax.xml
Index: program-sax.xml
===================================================================
RCS file: /home/cvs/xml-xerces/c/doc/program-sax.xml,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- program-sax.xml 20 Feb 2002 21:01:56 -0000 1.3
+++ program-sax.xml 21 May 2002 18:22:16 -0000 1.4
@@ -3,9 +3,8 @@
<s1 title="SAX1 Programming Guide">
- <anchor name="SAX1ProgGuide"/>
<anchor name="ConstructParser"/>
- <s2 title="Constructing a parser">
+ <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
@@ -13,21 +12,28 @@
required by the SAX API are provided using the HandlerBase
class supplied with &XercesCName;.</p>
-<source>int main (int argc, char* args[]) {
+<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"
- << DOMString(toCatch.getMessage()) << "\n";
+ << message << "\n";
+ delete [] message;
return 1;
}
char* xmlFile = "x1.xml";
SAXParser* parser = new SAXParser();
parser->setDoValidation(true); // optional.
- parser->setDoNamespaces(true); // optional
+ parser->setDoNamespaces(true); // optional
DocumentHandler* docHandler = new HandlerBase();
ErrorHandler* errHandler = (ErrorHandler*) docHandler;
@@ -38,19 +44,27 @@
parser->parse(xmlFile);
}
catch (const XMLException& toCatch) {
+ char* message = XMLString::transcode(toCatch.getMessage());
cout << "Exception message is: \n"
- << DOMString(toCatch.getMessage()) << "\n" ;
+ << message << "\n";
+ delete [] message;
return -1;
}
catch (const SAXParseException& toCatch) {
+ char* message = XMLString::transcode(toCatch.getMessage());
cout << "Exception message is: \n"
- << DOMString(toCatch.getMessage()) << "\n" ;
+ << message << "\n";
+ delete [] message;
return -1;
}
catch (...) {
cout << "Unexpected Exception \n" ;
return -1;
}
+
+ delete parser;
+ delete docHandler;
+ return 0;
}</source>
</s2>
@@ -106,15 +120,15 @@
MySAXHandler::startElement(const XMLCh* const name,
AttributeList& attributes)
{
- // transcode() is an user application defined function which
- // converts unicode strings to usual 'char *'. Look at
- // the sample program SAXCount for an example implementation.
- cout << "I saw element: " << transcode(name) << endl;
+ char* message = XMLString::transcode(name);
+ cout << "I saw element: "<< message << endl;
+ delete [] message;
}
MySAXHandler::fatalError(const SAXParseException& exception)
{
- cout << "Fatal Error: " << transcode(exception.getMessage())
+ char* message = XMLString::transcode(exception.getMessage());
+ cout << "Fatal Error: " << message
<< " at line: " << exception.getLineNumber()
<< endl;
}</source>
1.8 +23 -13 xml-xerces/c/doc/program-sax2.xml
Index: program-sax2.xml
===================================================================
RCS file: /home/cvs/xml-xerces/c/doc/program-sax2.xml,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- program-sax2.xml 7 May 2002 17:45:52 -0000 1.7
+++ program-sax2.xml 21 May 2002 18:22:16 -0000 1.8
@@ -3,7 +3,6 @@
<s1 title="SAX2 Programming Guide">
- <anchor name="SAX2ProgGuide"/>
<anchor name="ConstructParser2"/>
<s2 title="Constructing an XML Reader">
<p>In order to use &XercesCName; to parse XML files, you will
@@ -13,14 +12,23 @@
required by the SAX API are provided using the DefaultHandler
class supplied with &XercesCName;.</p>
-<source>int main (int argc, char* args[]) {
+<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"
- << DOMString(toCatch.getMessage()) << "\n";
+ cout << "Exception message is: \n"
+ << message << "\n";
+ delete [] message;
return 1;
}
@@ -37,24 +45,26 @@
parser->parse(xmlFile);
}
catch (const XMLException& toCatch) {
- delete parser;
+ char* message = XMLString::transcode(toCatch.getMessage());
cout << "Exception message is: \n"
- << DOMString(toCatch.getMessage()) << "\n" ;
+ << message << "\n";
+ delete [] message;
return -1;
}
catch (const SAXParseException& toCatch) {
- delete parser;
+ char* message = XMLString::transcode(toCatch.getMessage());
cout << "Exception message is: \n"
- << DOMString(toCatch.getMessage()) << "\n" ;
+ << message << "\n";
+ delete [] message;
return -1;
}
catch (...) {
- delete parser;
cout << "Unexpected Exception \n" ;
return -1;
}
delete parser;
+ delete defaultHandler;
return 0;
}</source>
</s2>
@@ -118,15 +128,15 @@
const XMLCh* const qname,
const Attributes& attrs)
{
- // transcode() is an user application defined function which
- // converts unicode strings to usual 'char *'. Look at
- // the sample program SAX2Count for an example implementation.
- cout << "I saw element: " << transcode(qname) << endl;
+ char* message = XMLString::transcode(name);
+ cout << "I saw element: "<< message << endl;
+ delete [] message;
}
MySAX2Handler::fatalError(const SAXParseException& exception)
{
- cout << "Fatal Error: " << transcode(exception.getMessage())
+ char* message = XMLString::transcode(exception.getMessage());
+ cout << "Fatal Error: " << message
<< " at line: " << exception.getLineNumber()
<< endl;
}</source>
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-cvs-help@xml.apache.org