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 &lt;xercesc/parsers/SAXParser.hpp>
  +#include &lt;xercesc/sax/HandlerBase.hpp>
  +#include &lt;xercesc/util/XMLString.hpp>
  +
  +int main (int argc, char* args[]) {
   
       try {
           XMLPlatformUtils::Initialize();
       }
       catch (const XMLException&amp; toCatch) {
  +        char* message = XMLString::transcode(toCatch.getMessage());
           cout &lt;&lt; "Error during initialization! :\n"
  -             &lt;&lt; DOMString(toCatch.getMessage()) &lt;&lt; "\n";
  +             &lt;&lt; message &lt;&lt; "\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&amp; toCatch) {
  +        char* message = XMLString::transcode(toCatch.getMessage());
           cout &lt;&lt; "Exception message is: \n"
  -             &lt;&lt; DOMString(toCatch.getMessage()) &lt;&lt; "\n" ;
  +             &lt;&lt; message &lt;&lt; "\n";
  +        delete [] message;
           return -1;
       }
       catch (const SAXParseException&amp; toCatch) {
  +        char* message = XMLString::transcode(toCatch.getMessage());
           cout &lt;&lt; "Exception message is: \n"
  -             &lt;&lt; DOMString(toCatch.getMessage()) &lt;&lt; "\n" ;
  +             &lt;&lt; message &lt;&lt; "\n";
  +        delete [] message;
           return -1;
       }
       catch (...) {
           cout &lt;&lt; "Unexpected Exception \n" ;
           return -1;
       }
  +
  +    delete parser;
  +    delete docHandler;
  +    return 0;
   }</source>
       </s2>
   
  @@ -106,15 +120,15 @@
   MySAXHandler::startElement(const XMLCh* const name,
                              AttributeList&amp; 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 &lt;&lt; "I saw element: " &lt;&lt; transcode(name) &lt;&lt; endl;
  +    char* message = XMLString::transcode(name);
  +    cout &lt;&lt; "I saw element: "&lt;&lt; message &lt;&lt; endl;
  +    delete [] message;
   }
   
   MySAXHandler::fatalError(const SAXParseException&amp; exception)
   {
  -    cout &lt;&lt; "Fatal Error: " &lt;&lt; transcode(exception.getMessage())
  +    char* message = XMLString::transcode(exception.getMessage());
  +    cout &lt;&lt; "Fatal Error: " &lt;&lt; message
            &lt;&lt; " at line: " &lt;&lt; exception.getLineNumber()
            &lt;&lt; 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 &lt;xercesc/sax2/SAX2XMLReader.hpp>
  +#include &lt;xercesc/sax2/XMLReaderFactory.hpp>
  +#include &lt;xercesc/sax2/DefaultHandler.hpp>
  +#include &lt;xercesc/util/XMLString.hpp>
  +
  +int main (int argc, char* args[]) {
   
       try {
           XMLPlatformUtils::Initialize();
       }
       catch (const XMLException&amp; toCatch) {
  +        char* message = XMLString::transcode(toCatch.getMessage());
           cout &lt;&lt; "Error during initialization! :\n"
  -             &lt;&lt; DOMString(toCatch.getMessage()) &lt;&lt; "\n";
  +        cout &lt;&lt; "Exception message is: \n"
  +             &lt;&lt; message &lt;&lt; "\n";
  +        delete [] message;
           return 1;
       }
   
  @@ -37,24 +45,26 @@
           parser->parse(xmlFile);
       }
       catch (const XMLException&amp; toCatch) {
  -        delete parser;
  +        char* message = XMLString::transcode(toCatch.getMessage());
           cout &lt;&lt; "Exception message is: \n"
  -             &lt;&lt; DOMString(toCatch.getMessage()) &lt;&lt; "\n" ;
  +             &lt;&lt; message &lt;&lt; "\n";
  +        delete [] message;
           return -1;
       }
       catch (const SAXParseException&amp; toCatch) {
  -        delete parser;
  +        char* message = XMLString::transcode(toCatch.getMessage());
           cout &lt;&lt; "Exception message is: \n"
  -             &lt;&lt; DOMString(toCatch.getMessage()) &lt;&lt; "\n" ;
  +             &lt;&lt; message &lt;&lt; "\n";
  +        delete [] message;
           return -1;
       }
       catch (...) {
  -        delete parser;
           cout &lt;&lt; "Unexpected Exception \n" ;
           return -1;
       }
   
       delete parser;
  +    delete defaultHandler;
       return 0;
   }</source>
       </s2>
  @@ -118,15 +128,15 @@
                               const   XMLCh* const    qname,
                               const   Attributes&amp;     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 &lt;&lt; "I saw element: " &lt;&lt; transcode(qname) &lt;&lt; endl;
  +    char* message = XMLString::transcode(name);
  +    cout &lt;&lt; "I saw element: "&lt;&lt; message &lt;&lt; endl;
  +    delete [] message;
   }
   
   MySAX2Handler::fatalError(const SAXParseException&amp; exception)
   {
  -    cout &lt;&lt; "Fatal Error: " &lt;&lt; transcode(exception.getMessage())
  +    char* message = XMLString::transcode(exception.getMessage());
  +    cout &lt;&lt; "Fatal Error: " &lt;&lt; message
            &lt;&lt; " at line: " &lt;&lt; exception.getLineNumber()
            &lt;&lt; endl;
   }</source>
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-cvs-help@xml.apache.org