You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by jp...@locus.apache.org on 2000/08/02 21:16:15 UTC

cvs commit: xml-xerces/c/samples/SAX2Print Makefile.in SAX2Print.cpp SAX2Print.hpp SAX2PrintHandlers.cpp SAX2PrintHandlers.hpp

jpolast     00/08/02 12:16:15

  Added:       c/samples/SAX2Print Makefile.in SAX2Print.cpp SAX2Print.hpp
                        SAX2PrintHandlers.cpp SAX2PrintHandlers.hpp
  Log:
  initial checkin of SAX2Print
  
  Revision  Changes    Path
  1.1                  xml-xerces/c/samples/SAX2Print/Makefile.in
  
  Index: Makefile.in
  ===================================================================
  #
  # The Apache Software License, Version 1.1
  # 
  # Copyright (c) 1999-2000 The Apache Software Foundation.  All rights
  # reserved.
  # 
  # Redistribution and use in source and binary forms, with or without
  # modification, are permitted provided that the following conditions
  # are met:
  # 
  # 1. Redistributions of source code must retain the above copyright
  #    notice, this list of conditions and the following disclaimer. 
  # 
  # 2. Redistributions in binary form must reproduce the above copyright
  #    notice, this list of conditions and the following disclaimer in
  #    the documentation and/or other materials provided with the
  #    distribution.
  # 
  # 3. The end-user documentation included with the redistribution,
  #    if any, must include the following acknowledgment:  
  #       "This product includes software developed by the
  #        Apache Software Foundation (http://www.apache.org/)."
  #    Alternately, this acknowledgment may appear in the software itself,
  #    if and wherever such third-party acknowledgments normally appear.
  # 
  # 4. The names "Xerces" and "Apache Software Foundation" must
  #    not be used to endorse or promote products derived from this
  #    software without prior written permission. For written 
  #    permission, please contact apache\@apache.org.
  # 
  # 5. Products derived from this software may not be called "Apache",
  #    nor may "Apache" appear in their name, without prior written
  #    permission of the Apache Software Foundation.
  # 
  # THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  # WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  # DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  # ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  # USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  # OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  # SUCH DAMAGE.
  # ====================================================================
  # 
  # This software consists of voluntary contributions made by many
  # individuals on behalf of the Apache Software Foundation, and was
  # originally based on software copyright (c) 1999, International
  # Business Machines, Inc., http://www.ibm.com .  For more information
  # on the Apache Software Foundation, please see
  # <http://www.apache.org/>.
  # 
  #
  # $Id: Makefile.in,v 1.1 2000/08/02 19:16:14 jpolast Exp $
  #
  
  ###################################################################
  #                    IMPORTANT NOTE                               #
  ###################################################################
  # If you are going to do the OS390BATCH build, make sure you have #
  # the OS390BATCH environment variable set.                        #
  #                                                                 #
  #   export OS390BATCH=1                                           #
  #                                                                 #
  ###################################################################
  
  PLATFORM = @platform@
  COMPILER = @compiler@
  CXXFLAGS = @cxxflags@
  CFLAGS = @cflags@
  PREFIX = @prefix@
  
  include ../../version.incl
  include ../Makefile.incl
  
  APP_NAME=SAX2Print
  
  OUTDIR= ${XERCESCROOT}/bin/obj/${APP_NAME}
  EXEC=	${XERCESCROOT}/bin
  OBJS=	${OUTDIR}/SAX2Print.o ${OUTDIR}/SAX2PrintHandlers.o
  SRC=	${XERCESCROOT}/samples/${APP_NAME}
  HEADER_FILES=${SRC}/SAX2Print.hpp ${SRC}/SAX2PrintHandlers.hpp
  
  ## OS390BATCH
  ifeq (${OS390BATCH},1)
  BATCH_TARGET= "//'${LOADMOD}(${APP_NAME})'"
  all:: makedir ${BATCH_TARGET}
  else
  all:: makedir ${EXEC}/${APP_NAME}
  endif
  
  makedir::
  	-mkdir -p $(OUTDIR)
  
  ${EXEC}/${APP_NAME}:: ${OBJS}
  	${LINK} ${PLATFORM_LIB_LINK_OPTIONS} ${OBJS} -o $@ ${LIBRARY_SEARCH_PATHS} ${LIBRARY_NAMES} ${EXTRA_LINK_OPTIONS} 
  ${BATCH_TARGET}:: ${OBJS}
  	${LINK} ${PLATFORM_LIB_LINK_OPTIONS} ${OBJS} -o $@ ${LIBRARY_SEARCH_PATHS} ${LIBRARY_NAMES} ${EXTRA_LINK_OPTIONS} 
  
  $(OUTDIR)/SAX2Print.o:: ${SRC}/SAX2Print.cpp ${HEADER_FILES}
  	${CC} ${CMP} $(INCLUDES) -o $(OUTDIR)/SAX2Print.o ${SRC}/SAX2Print.cpp
  
  $(OUTDIR)/SAX2PrintHandlers.o:: ${SRC}/SAX2PrintHandlers.cpp ${HEADER_FILES}
  	${CC} ${CMP} $(INCLUDES) -o $(OUTDIR)/SAX2PrintHandlers.o ${SRC}/SAX2PrintHandlers.cpp
  
  clean::
  	rm -f ${OBJS} ${EXEC}/${APP_NAME}
  
  distclean::	clean
  	rm -f Makefile
  
  
  
  1.1                  xml-xerces/c/samples/SAX2Print/SAX2Print.cpp
  
  Index: SAX2Print.cpp
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2000 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Xerces" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written
   *    permission, please contact apache\@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation, and was
   * originally based on software copyright (c) 1999, International
   * Business Machines, Inc., http://www.ibm.com .  For more information
   * on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  /*
   * $Log: SAX2Print.cpp,v $
   * Revision 1.1  2000/08/02 19:16:14  jpolast
   * initial checkin of SAX2Print
   *
   *
   */
  
  
  // ---------------------------------------------------------------------------
  //  Includes
  // ---------------------------------------------------------------------------
  #include <util/PlatformUtils.hpp>
  #include <util/TransService.hpp>
  #include <sax2/SAX2XMLReader.hpp>
  #include <sax2/XMLReaderFactory.hpp>
  #include "SAX2Print.hpp"
  
  
  // ---------------------------------------------------------------------------
  //  Local data
  //
  //  encodingName
  //      The encoding we are to output in. If not set on the command line,
  //      then it is defaulted to LATIN1.
  //
  //  xmlFile
  //      The path to the file to parser. Set via command line.
  //
  //  valScheme
  //      Indicates what validation scheme to use. It defaults to 'auto', but
  //      can be set via the -v= command.
  //
  //	expandNamespaces
  //		Indicates if the output should expand the namespaces Alias with
  //		their URI's, defaults to false, can be set via the command line -e
  // ---------------------------------------------------------------------------
  static const char*              encodingName    = "LATIN1";
  static XMLFormatter::UnRepFlags unRepFlags      = XMLFormatter::UnRep_CharRef;
  static char*                    xmlFile         = 0;
  static SAXParser::ValSchemes    valScheme       = SAXParser::Val_Auto;
  static bool						expandNamespaces= false ;
  
  
  
  // ---------------------------------------------------------------------------
  //  Local helper methods
  // ---------------------------------------------------------------------------
  static void usage()
  {
      cout <<  "\nUsage: SAX2Print [options] file\n"
               "This program prints the data returned by the various SAX2\n"
               "handlers for the specified input file. Options are NOT case\n"
               "sensitive.\n\n"
               "Options:\n"
               "    -u=xxx      Handle unrepresentable chars [fail | rep | ref*]\n"
               "    -v=xxx      Validation scheme [always | never | auto*]\n"
               "    -e          Expand Namespace Alias with URI's.\n"
               "    -x=XXX      Use a particular encoding for output (LATIN1*).\n"
               "    -?          Show this help\n\n"
               "  * = Default if not provided explicitly\n\n"
               "The parser has intrinsic support for the following encodings:\n"
               "    UTF-8, USASCII, ISO8859-1, UTF-16[BL]E, UCS-4[BL]E,\n"
               "    WINDOWS-1252, IBM1140, IBM037\n"
           <<  endl;
  }
  
  
  
  // ---------------------------------------------------------------------------
  //  Program entry point
  // ---------------------------------------------------------------------------
  int main(int argC, char* argV[])
  {
      // Initialize the XML4C2 system
      try
      {
           XMLPlatformUtils::Initialize();
      }
  
      catch (const XMLException& toCatch)
      {
           cerr << "Error during initialization! :\n"
                << StrX(toCatch.getMessage()) << endl;
           return 1;
      }
  
      // Check command line and extract arguments.
      if (argC < 2)
      {
          usage();
          XMLPlatformUtils::Terminate();
          return 1;
      }
  
      // Watch for special case help request
      if ((argC == 2) && !strcmp(argV[1], "-?"))
      {
          usage();
          XMLPlatformUtils::Terminate();
          return 2;
      }
  
      int parmInd;
      for (parmInd = 1; parmInd < argC; parmInd++)
      {
          // Break out on first parm not starting with a dash
          if (argV[parmInd][0] != '-')
              break;
  
          if (!strncmp(argV[parmInd], "-v=", 3)
          ||  !strncmp(argV[parmInd], "-V=", 3))
          {
              const char* const parm = &argV[parmInd][3];
  
              if (!strcmp(parm, "never"))
                  valScheme = SAXParser::Val_Never;
              else if (!strcmp(parm, "auto"))
                  valScheme = SAXParser::Val_Auto;
              else if (!strcmp(parm, "always"))
                  valScheme = SAXParser::Val_Always;
              else
              {
                  cerr << "Unknown -v= value: " << parm << endl;
                  return 2;
              }
          }
           else if (!strcmp(argV[parmInd], "-e")
                ||  !strcmp(argV[parmInd], "-E"))
          {
              expandNamespaces = true;
          }
           else if (!strncmp(argV[parmInd], "-x=", 3)
                ||  !strncmp(argV[parmInd], "-X=", 3))
          {
              // Get out the encoding name
              encodingName = &argV[parmInd][3];
          }
           else if (!strncmp(argV[parmInd], "-u=", 3)
                ||  !strncmp(argV[parmInd], "-U=", 3))
          {
              const char* const parm = &argV[parmInd][3];
  
              if (!strcmp(parm, "fail"))
                  unRepFlags = XMLFormatter::UnRep_Fail;
              else if (!strcmp(parm, "rep"))
                  unRepFlags = XMLFormatter::UnRep_Replace;
              else if (!strcmp(parm, "ref"))
                  unRepFlags = XMLFormatter::UnRep_CharRef;
              else
              {
                  cerr << "Unknown -u= value: " << parm << endl;
                  return 2;
              }
          }
           else
          {
              cerr << "Unknown option '" << argV[parmInd]
                   << "', ignoring it\n" << endl;
          }
      }
  
      //
      //  And now we have to have only one parameter left and it must be
      //  the file name.
      //
      if (parmInd + 1 != argC)
      {
          usage();
          return 1;
      }
      xmlFile = argV[parmInd];
  
      //
      //  Create a SAX parser object. Then, according to what we were told on
      //  the command line, set it to validate or not.
      //
      SAX2XMLReader* parser = XMLReaderFactory::createXMLReader();
  	if (valScheme == SAXParser::Val_Auto)
  	{
  	  parser->setFeature(XMLString::transcode("http://xml.org/sax/features/validation"), true);
  	  parser->setFeature(XMLString::transcode("http://apache.org/xml/features/validation/dynamic"), true);
  	}
      if (valScheme == SAXParser::Val_Never)
  	{
  	  parser->setFeature(XMLString::transcode("http://xml.org/sax/features/validation"), false);
  	}
  	if (valScheme == SAXParser::Val_Always)
  	{
  	  parser->setFeature(XMLString::transcode("http://xml.org/sax/features/validation"), true);
  	  parser->setFeature(XMLString::transcode("http://apache.org/xml/features/validation/dynamic"), false);
  	}
  
      //
      //  Create the handler object and install it as the document and error
      //  handler for the parser. Then parse the file and catch any exceptions
      //  that propogate out
      //
      try
      {
          SAX2PrintHandlers handler(encodingName, unRepFlags, expandNamespaces);
          parser->setContentHandler(&handler);
          parser->setErrorHandler(&handler);
          parser->parse(xmlFile);
      }
  
      catch (const XMLException& toCatch)
      {
          cerr << "\nAn error occured\n  Error: "
               << StrX(toCatch.getMessage())
               << "\n" << endl;
          return -1;
      }
  
      // And call the termination method
      XMLPlatformUtils::Terminate();
  
      return 0;
  }
  
  
  
  
  1.1                  xml-xerces/c/samples/SAX2Print/SAX2Print.hpp
  
  Index: SAX2Print.hpp
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2000 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Xerces" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written
   *    permission, please contact apache\@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation, and was
   * originally based on software copyright (c) 1999, International
   * Business Machines, Inc., http://www.ibm.com .  For more information
   * on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  /*
   * $Log: SAX2Print.hpp,v $
   * Revision 1.1  2000/08/02 19:16:14  jpolast
   * initial checkin of SAX2Print
   *
   *
   */
  
  // ---------------------------------------------------------------------------
  //  Includes for all the program files to see
  // ---------------------------------------------------------------------------
  #include <string.h>
  #include <iostream.h>
  #include <stdlib.h>
  #include "SAX2PrintHandlers.hpp"
  
  
  // ---------------------------------------------------------------------------
  //  This is a simple class that lets us do easy (though not terribly efficient)
  //  trancoding of XMLCh data to local code page for display.
  // ---------------------------------------------------------------------------
  class StrX
  {
  public :
      // -----------------------------------------------------------------------
      //  Constructors and Destructor
      // -----------------------------------------------------------------------
      StrX(const XMLCh* const toTranscode)
      {
          // Call the private transcoding method
          fLocalForm = XMLString::transcode(toTranscode);
      }
  
      ~StrX()
      {
          delete [] fLocalForm;
      }
  
      // -----------------------------------------------------------------------
      //  Getter methods
      // -----------------------------------------------------------------------
      const char* localForm() const
      {
          return fLocalForm;
      }
  
  private :
      // -----------------------------------------------------------------------
      //  Private data members
      //
      //  fLocalForm
      //      This is the local code page form of the string.
      // -----------------------------------------------------------------------
      char*   fLocalForm;
  };
  
  inline ostream& operator<<(ostream& target, const StrX& toDump)
  {
      target << toDump.localForm();
      return target;
  }
  
  
  
  1.1                  xml-xerces/c/samples/SAX2Print/SAX2PrintHandlers.cpp
  
  Index: SAX2PrintHandlers.cpp
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2000 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Xerces" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written
   *    permission, please contact apache\@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation, and was
   * originally based on software copyright (c) 1999, International
   * Business Machines, Inc., http://www.ibm.com .  For more information
   * on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  /*
   * $Log: SAX2PrintHandlers.cpp,v $
   * Revision 1.1  2000/08/02 19:16:14  jpolast
   * initial checkin of SAX2Print
   *
   *
   */
  
  
  
  // ---------------------------------------------------------------------------
  //  Includes
  // ---------------------------------------------------------------------------
  #include <util/XMLUniDefs.hpp>
  #include <sax2/Attributes.hpp>
  #include "SAX2Print.hpp"
  
  
  // ---------------------------------------------------------------------------
  //  Local const data
  //
  //  Note: This is the 'safe' way to do these strings. If you compiler supports
  //        L"" style strings, and portability is not a concern, you can use
  //        those types constants directly.
  // ---------------------------------------------------------------------------
  static const XMLCh  gEndElement[] = { chOpenAngle, chForwardSlash, chNull };
  static const XMLCh  gEndPI[] = { chQuestion, chCloseAngle, chNull };
  static const XMLCh  gStartPI[] = { chOpenAngle, chQuestion, chNull };
  static const XMLCh  gXMLDecl1[] =
  {
          chOpenAngle, chQuestion, chLatin_x, chLatin_m, chLatin_l
      ,   chSpace, chLatin_v, chLatin_e, chLatin_r, chLatin_s, chLatin_i
      ,   chLatin_o, chLatin_n, chEqual, chDoubleQuote, chDigit_1, chPeriod
      ,   chDigit_0, chDoubleQuote, chSpace, chLatin_e, chLatin_n, chLatin_c
      ,   chLatin_o, chLatin_d, chLatin_i, chLatin_n, chLatin_g, chEqual
      ,   chDoubleQuote, chNull
  };
  
  static const XMLCh  gXMLDecl2[] =
  {
          chDoubleQuote, chQuestion, chCloseAngle
      ,   chCR, chLF, chNull
  };
  
  
  
  
  // ---------------------------------------------------------------------------
  //  SAX2PrintHandlers: Constructors and Destructor
  // ---------------------------------------------------------------------------
  SAX2PrintHandlers::SAX2PrintHandlers( const   char* const              encodingName
                                      , const XMLFormatter::UnRepFlags unRepFlags
  									, const bool					 expandNamespaces) :
  
      fFormatter
      (
          encodingName
          , this
          , XMLFormatter::NoEscapes
          , unRepFlags
      ),
  	fExpandNS ( expandNamespaces )
  {
      //
      //  Go ahead and output an XML Decl with our known encoding. This
      //  is not the best answer, but its the best we can do until we
      //  have SAX2 support.
      //
      fFormatter << gXMLDecl1 << fFormatter.getEncodingName() << gXMLDecl2;
  }
  
  SAX2PrintHandlers::~SAX2PrintHandlers()
  {
  }
  
  
  // ---------------------------------------------------------------------------
  //  SAX2PrintHandlers: Overrides of the output formatter target interface
  // ---------------------------------------------------------------------------
  void SAX2PrintHandlers::writeChars(const XMLByte* const toWrite)
  {
      // For this one, just dump them to the standard output
      // Surprisingly, Solaris was the only platform on which
      // required the char* cast to print out the string correctly.
      // Without the cast, it was printing the pointer value in hex.
      // Quite annoying, considering every other platform printed
      // the string with the explicit cast to char* below.
      cout << (char *) toWrite;
  	cout.flush();
  }
  
  
  // ---------------------------------------------------------------------------
  //  SAX2PrintHandlers: Overrides of the SAX ErrorHandler interface
  // ---------------------------------------------------------------------------
  void SAX2PrintHandlers::error(const SAXParseException& e)
  {
      cerr << "\nError at file " << StrX(e.getSystemId())
  		 << ", line " << e.getLineNumber()
  		 << ", char " << e.getColumnNumber()
           << "\n  Message: " << StrX(e.getMessage()) << endl;
  }
  
  void SAX2PrintHandlers::fatalError(const SAXParseException& e)
  {
      cerr << "\nFatal Error at file " << StrX(e.getSystemId())
  		 << ", line " << e.getLineNumber()
  		 << ", char " << e.getColumnNumber()
           << "\n  Message: " << StrX(e.getMessage()) << endl;
  }
  
  void SAX2PrintHandlers::warning(const SAXParseException& e)
  {
      cerr << "\nWarning at file " << StrX(e.getSystemId())
  		 << ", line " << e.getLineNumber()
  		 << ", char " << e.getColumnNumber()
           << "\n  Message: " << StrX(e.getMessage()) << endl;
  }
  
  
  // ---------------------------------------------------------------------------
  //  SAX2PrintHandlers: Overrides of the SAX DTDHandler interface
  // ---------------------------------------------------------------------------
  void SAX2PrintHandlers::unparsedEntityDecl(const     XMLCh* const name
                                            , const   XMLCh* const publicId
                                            , const   XMLCh* const systemId
                                            , const   XMLCh* const notationName)
  {
      // Not used at this time
  }
  
  
  void SAX2PrintHandlers::notationDecl(const   XMLCh* const name
                                      , const XMLCh* const publicId
                                      , const XMLCh* const systemId)
  {
      // Not used at this time
  }
  
  
  // ---------------------------------------------------------------------------
  //  SAX2PrintHandlers: Overrides of the SAX DocumentHandler interface
  // ---------------------------------------------------------------------------
  void SAX2PrintHandlers::characters(const     XMLCh* const    chars
                                    , const   unsigned int    length)
  {
      fFormatter.formatBuf(chars, length, XMLFormatter::CharEscapes);
  }
  
  
  void SAX2PrintHandlers::endDocument()
  {
  }
  
  
  void SAX2PrintHandlers::endElement(const XMLCh* const uri, 
  								 const XMLCh* const localname, 
  								 const XMLCh* const qname)
  {
      // No escapes are legal here
      fFormatter << XMLFormatter::NoEscapes << gEndElement ;
  	if ( fExpandNS )
  		fFormatter << uri << chColon << localname << chCloseAngle;
  	else
  		fFormatter << qname << chCloseAngle;
  }
  
  
  void SAX2PrintHandlers::ignorableWhitespace( const   XMLCh* const chars
                                              ,const  unsigned int length)
  {
      fFormatter.formatBuf(chars, length, XMLFormatter::NoEscapes);
  }
  
  
  void SAX2PrintHandlers::processingInstruction(const  XMLCh* const target
                                              , const XMLCh* const data)
  {
      fFormatter << XMLFormatter::NoEscapes << gStartPI  << target;
      if (data)
          fFormatter << chSpace << data;
      fFormatter << XMLFormatter::NoEscapes << gEndPI;
  }
  
  
  void SAX2PrintHandlers::startDocument()
  {
  }
  
  
  void SAX2PrintHandlers::startElement(const   XMLCh* const    uri,
  									const   XMLCh* const    localname,
  									const   XMLCh* const    qname
                                      ,       Attributes&		attributes)
  {
      // The name has to be representable without any escapes
      fFormatter  << XMLFormatter::NoEscapes << chOpenAngle ;
  	if ( fExpandNS )
  		fFormatter << uri << chColon << localname ;
  	else
  		fFormatter << qname ;
  
      unsigned int len = attributes.getLength();
      for (unsigned int index = 0; index < len; index++)
      {
          //
          //  Again the name has to be completely representable. But the
          //  attribute can have refs and requires the attribute style
          //  escaping.
          //
          fFormatter  << XMLFormatter::NoEscapes << chSpace ;
  		if ( fExpandNS )
  			fFormatter  << attributes.getURI(index) << chColon << attributes.getLocalName(index) ;
  		else
  			fFormatter  << attributes.getQName(index) ;
  
  		fFormatter  << chEqual << chDoubleQuote
                      << XMLFormatter::AttrEscapes
  		            << attributes.getValue(index)
                      << XMLFormatter::NoEscapes
                      << chDoubleQuote;
      }
      fFormatter << chCloseAngle;
  }
  
  
  
  1.1                  xml-xerces/c/samples/SAX2Print/SAX2PrintHandlers.hpp
  
  Index: SAX2PrintHandlers.hpp
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2000 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Xerces" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written
   *    permission, please contact apache\@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation, and was
   * originally based on software copyright (c) 1999, International
   * Business Machines, Inc., http://www.ibm.com .  For more information
   * on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  /*
   * $Log: SAX2PrintHandlers.hpp,v $
   * Revision 1.1  2000/08/02 19:16:14  jpolast
   * initial checkin of SAX2Print
   *
   *
   */
  
  #include    <sax2/DefaultHandler.hpp>
  #include    <framework/XMLFormatter.hpp>
  
  class SAX2PrintHandlers : public DefaultHandler, private XMLFormatTarget
  {
  public:
      // -----------------------------------------------------------------------
      //  Constructors
      // -----------------------------------------------------------------------
      SAX2PrintHandlers
      (
          const   char* const                 encodingName
          , const XMLFormatter::UnRepFlags    unRepFlags
  		, const bool						expandNamespaces
      );
      ~SAX2PrintHandlers();
  
  
      // -----------------------------------------------------------------------
      //  Implementations of the format target interface
      // -----------------------------------------------------------------------
      void writeChars
      (
          const   XMLByte* const  toWrite
      );
  
  
      // -----------------------------------------------------------------------
      //  Implementations of the SAX DocumentHandler interface
      // -----------------------------------------------------------------------
      void endDocument();
  
      void endElement( const XMLCh* const uri, 
  					 const XMLCh* const localname, 
  					 const XMLCh* const qname);
  
      void characters(const XMLCh* const chars, const unsigned int length);
  
      void ignorableWhitespace
      (
          const   XMLCh* const    chars
          , const unsigned int    length
      );
  
      void processingInstruction
      (
          const   XMLCh* const    target
          , const XMLCh* const    data
      );
  
      void startDocument();
  
      void startElement(	const   XMLCh* const    uri,
  						const   XMLCh* const    localname,
  						const   XMLCh* const    qname
  							, Attributes&		attributes);
  
  
  
      // -----------------------------------------------------------------------
      //  Implementations of the SAX ErrorHandler interface
      // -----------------------------------------------------------------------
      void warning(const SAXParseException& exception);
      void error(const SAXParseException& exception);
      void fatalError(const SAXParseException& exception);
  
  
  
      // -----------------------------------------------------------------------
      //  Implementation of the SAX DTDHandler interface
      // -----------------------------------------------------------------------
      void notationDecl
      (
          const   XMLCh* const    name
          , const XMLCh* const    publicId
          , const XMLCh* const    systemId
      );
  
      void unparsedEntityDecl
      (
          const   XMLCh* const    name
          , const XMLCh* const    publicId
          , const XMLCh* const    systemId
          , const XMLCh* const    notationName
      );
  
  private :
      // -----------------------------------------------------------------------
      //  Private data members
      //
      //  fFormatter
      //      This is the formatter object that is used to output the data
      //      to the target. It is set up to format to the standard output
      //      stream.
      // -----------------------------------------------------------------------
      XMLFormatter    fFormatter;
  	bool			fExpandNS ;
  };