You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by pe...@apache.org on 2002/05/29 00:37:33 UTC

cvs commit: xml-xerces/c/samples/DOMPrint Makefile.in DOMPrint.cpp

peiyongz    02/05/28 15:37:33

  Modified:    c/samples/DOMPrint Makefile.in DOMPrint.cpp
  Log:
  DOM3 Save Interface: DOMWriter/DOMWriterFilter
  
  Revision  Changes    Path
  1.10      +6 -3      xml-xerces/c/samples/DOMPrint/Makefile.in
  
  Index: Makefile.in
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/samples/DOMPrint/Makefile.in,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- Makefile.in	9 Nov 2000 01:37:17 -0000	1.9
  +++ Makefile.in	28 May 2002 22:37:33 -0000	1.10
  @@ -54,7 +54,7 @@
   # <http://www.apache.org/>.
   # 
   #
  -# $Id: Makefile.in,v 1.9 2000/11/09 01:37:17 andyh Exp $
  +# $Id: Makefile.in,v 1.10 2002/05/28 22:37:33 peiyongz Exp $
   #
   
   ###################################################################
  @@ -82,9 +82,9 @@
   
   OUTDIR= ${XERCESCROOT}/bin/obj/${APP_NAME}
   EXEC=	${XERCESCROOT}/bin
  -OBJS=	${OUTDIR}/DOMPrint.o ${OUTDIR}/DOMTreeErrorReporter.o
  +OBJS=	${OUTDIR}/DOMPrint.o ${OUTDIR}/DOMTreeErrorReporter.o ${OUTDIR}/DOMPrintFilter.o
   SRC=	${XERCESCROOT}/samples/${APP_NAME}
  -HEADER_FILES=${SRC}/DOMTreeErrorReporter.hpp
  +HEADER_FILES=${SRC}/DOMTreeErrorReporter.hpp ${SRC}/DOMPrintFilter.hpp
   
   ## OS390BATCH
   ifeq (${OS390BATCH},1)
  @@ -108,6 +108,9 @@
   $(OUTDIR)/DOMTreeErrorReporter.o:: ${SRC}/DOMTreeErrorReporter.cpp ${HEADER_FILES}
   	${CC} ${CMP} $(INCLUDES) -o $(OUTDIR)/DOMTreeErrorReporter.o ${SRC}/DOMTreeErrorReporter.cpp
   
  +$(OUTDIR)/DOMPrintFilter.o:: ${SRC}/DOMPrintFilter.cpp ${HEADER_FILES}
  +	${CC} ${CMP} $(INCLUDES) -o $(OUTDIR)/DOMPrintFilter.o ${SRC}/DOMPrintFilter.cpp
  +	
   clean::
   	rm -f ${OBJS} ${EXEC}/${APP_NAME}
   
  
  
  
  1.39      +167 -454  xml-xerces/c/samples/DOMPrint/DOMPrint.cpp
  
  Index: DOMPrint.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/samples/DOMPrint/DOMPrint.cpp,v
  retrieving revision 1.38
  retrieving revision 1.39
  diff -u -r1.38 -r1.39
  --- DOMPrint.cpp	21 May 2002 19:18:18 -0000	1.38
  +++ DOMPrint.cpp	28 May 2002 22:37:33 -0000	1.39
  @@ -1,7 +1,7 @@
   /*
    * The Apache Software License, Version 1.1
    *
  - * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights
  + * Copyright (c) 2002 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -55,23 +55,32 @@
    */
   
   /*
  - * $Id: DOMPrint.cpp,v 1.38 2002/05/21 19:18:18 tng Exp $
  + * $Id: DOMPrint.cpp,v 1.39 2002/05/28 22:37:33 peiyongz Exp $
    */
   
  -
   // ---------------------------------------------------------------------------
  -//  This sample program which invokes the DOMParser to build a DOM tree for
  -//  the specified input file. It then walks the tree, and prints out the data
  -//  as an XML file.
  +//  This sample program invokes the XercesDOMParser to build a DOM tree for
  +//  the specified input file. It then invokes DOMWriter::writeToString() to 
  +//  serialize the resultant DOM tree in to an XMLCh stream, if no error occurs 
  +//  during the parsing. 
  +//
  +//  If "-wverify" is specified, the parser will parse the resultant string
  +//  for the second time to verify the serialized result from the first parse,
  +//  and invokes DOMWriter::writeNode() to serialize the resultant DOM tree.
  +//  
  +//  Note: since any combination of characters can be the end of line sequence,
  +//        the resultant XML stream may NOT be well formed any more.
  +//
  +//        In case a filter is specified, and which does filter out some part 
  +//        of the original XML document, thus the resultant XML stream may not
  +//        valid.
   //
   //   Limitations:
   //      1.  The encoding="xxx" clause in the XML header should reflect
   //          the system local code page, but does not.
   //      2.  Cases where the XML data contains characters that can not
   //          be represented in the system local code page are not handled.
  -//      3.  Enabled namespace processing won't affect the output, since
  -//          DOM doesn't do namespace yet. But it will confirm that all
  -//          prefixes are correctly mapped, else you'll get errors.
  +//
   // ---------------------------------------------------------------------------
   
   
  @@ -79,135 +88,19 @@
   //  Includes
   // ---------------------------------------------------------------------------
   #include <xercesc/util/PlatformUtils.hpp>
  -#include <xercesc/util/XMLString.hpp>
  -#include <xercesc/util/XMLUniDefs.hpp>
  -#include <xercesc/framework/XMLFormatter.hpp>
  -#include <xercesc/util/TranscodingException.hpp>
  -
  -
  -#include <xercesc/dom/DOMException.hpp>
  -
  -#include <xercesc/parsers/XercesDOMParser.hpp>
   #include <xercesc/dom/DOM.hpp>
  +#include <xercesc/dom/impl/DOMWriterImpl.hpp>
  +#include <xercesc/dom/impl/DOMDocumentTypeImpl.hpp>
  +#include <xercesc/framework/StdOutFormatTarget.hpp>
  +#include <xercesc/framework/MemBufInputSource.hpp>
  +#include <xercesc/parsers/XercesDOMParser.hpp>
  +
   #include "DOMTreeErrorReporter.hpp"
  +#include "DOMPrintFilter.hpp"
  +
   #include <string.h>
   #include <stdlib.h>
   
  -
  -
  -// ---------------------------------------------------------------------------
  -//  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, chNull
  -};
  -static const XMLCh  gXMLDecl2[] =
  -{
  -        chDoubleQuote, chSpace, chLatin_e, chLatin_n, chLatin_c
  -    ,   chLatin_o, chLatin_d, chLatin_i, chLatin_n, chLatin_g, chEqual
  -    ,   chDoubleQuote, chNull
  -};
  -static const XMLCh  gXMLDecl3[] =
  -{
  -        chDoubleQuote, chQuestion, chCloseAngle
  -    ,   chLF, chNull
  -};
  -
  -static const XMLCh  gStartCDATA[] =
  -{
  -        chOpenAngle, chBang, chOpenSquare, chLatin_C, chLatin_D,
  -        chLatin_A, chLatin_T, chLatin_A, chOpenSquare, chNull
  -};
  -
  -static const XMLCh  gEndCDATA[] =
  -{
  -    chCloseSquare, chCloseSquare, chCloseAngle, chNull
  -};
  -static const XMLCh  gStartComment[] =
  -{
  -    chOpenAngle, chBang, chDash, chDash, chNull
  -};
  -
  -static const XMLCh  gEndComment[] =
  -{
  -    chDash, chDash, chCloseAngle, chNull
  -};
  -
  -static const XMLCh  gStartDoctype[] =
  -{
  -    chOpenAngle, chBang, chLatin_D, chLatin_O, chLatin_C, chLatin_T,
  -    chLatin_Y, chLatin_P, chLatin_E, chSpace, chNull
  -};
  -static const XMLCh  gPublic[] =
  -{
  -    chLatin_P, chLatin_U, chLatin_B, chLatin_L, chLatin_I,
  -    chLatin_C, chSpace, chDoubleQuote, chNull
  -};
  -static const XMLCh  gSystem[] =
  -{
  -    chLatin_S, chLatin_Y, chLatin_S, chLatin_T, chLatin_E,
  -    chLatin_M, chSpace, chDoubleQuote, chNull
  -};
  -static const XMLCh  gStartEntity[] =
  -{
  -    chOpenAngle, chBang, chLatin_E, chLatin_N, chLatin_T, chLatin_I,
  -    chLatin_T, chLatin_Y, chSpace, chNull
  -};
  -static const XMLCh  gNotation[] =
  -{
  -    chLatin_N, chLatin_D, chLatin_A, chLatin_T, chLatin_A,
  -    chSpace, chDoubleQuote, chNull
  -};
  -
  -
  -
  -// ---------------------------------------------------------------------------
  -//  Local classes
  -// ---------------------------------------------------------------------------
  -
  -class DOMPrintFormatTarget : public XMLFormatTarget
  -{
  -public:
  -    DOMPrintFormatTarget()  {};
  -    ~DOMPrintFormatTarget() {};
  -
  -    // -----------------------------------------------------------------------
  -    //  Implementations of the format target interface
  -    // -----------------------------------------------------------------------
  -
  -    void writeChars(const   XMLByte* const  toWrite,
  -                    const   unsigned int    count,
  -                            XMLFormatter * const formatter)
  -    {
  -        // 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.write((char *) toWrite, (int) count);
  -    };
  -
  -private:
  -    // -----------------------------------------------------------------------
  -    //  Unimplemented methods.
  -    // -----------------------------------------------------------------------
  -    DOMPrintFormatTarget(const DOMPrintFormatTarget& other);
  -    void operator=(const DOMPrintFormatTarget& rhs);
  -};
  -
  -
  -
   // ---------------------------------------------------------------------------
   //  Local data
   //
  @@ -231,6 +124,9 @@
   //      The encoding we are to output in. If not set on the command line,
   //      then it is defaults to the encoding of the input XML file.
   //
  +//  gEndOfLineSequence
  +//      The end of line sequence we are to output. 
  +//
   //  gValScheme
   //      Indicates what validation scheme to use. It defaults to 'auto', but
   //      can be set via the -v= command.
  @@ -240,25 +136,26 @@
   static bool                     gDoNamespaces          = false;
   static bool                     gDoSchema              = false;
   static bool                     gSchemaFullChecking    = false;
  -static bool                     gDoCreate              = false;
  -static const XMLCh*             gEncodingName          = 0;
  -static bool                     gEncodingNameisOnHeap  = false;
  -static XMLFormatter::UnRepFlags gUnRepFlags            = XMLFormatter::UnRep_CharRef;
  -static XercesDOMParser::ValSchemes    gValScheme             = XercesDOMParser::Val_Auto;
  -static XMLFormatter*            gFormatter             = 0;
  -
  -
  -
  -// ---------------------------------------------------------------------------
  -//  Forward references
  -// ---------------------------------------------------------------------------
  -void     usage();
  -ostream& operator<<(ostream& target, const XMLCh * toWrite);
  -ostream& operator<<(ostream& target, DOMNode *toWrite);
  -// XMLFormatter& operator<< (XMLFormatter& strm, const XMLCh *s);
  +static bool                     gDoCreate              = true;
   
  +// options for DOMWriter's features
  +static const XMLCh*             gEncodingName          = 0;
  +static const XMLCh*             gEndOfLineSequence     = 0;
   
  +static bool                     gCanonicalForm               = false;
  +static bool                     gFormatPrettyPrint           = false;
  +static bool                     gNormalizeCharacters         = false;
  +static bool                     gValidation                  = false;
  +static bool                     gSplitCdataSections          = true;
  +static bool                     gDiscardDefaultContent       = true;
  +static bool                     gEntityReferenceExpansion    = true;
  +static bool                     gWhitespaceInElementContent  = true;
  +
  +static bool                     gVerifyResult                = false;
  +static bool                     gUseFilter                   = false;
  +static DOMPrintFilter          *gFilter = 0;
   
  +static XercesDOMParser::ValSchemes    gValScheme       = XercesDOMParser::Val_Auto;
   
   // ---------------------------------------------------------------------------
   //
  @@ -270,18 +167,27 @@
       cout << "\nUsage:\n"
               "    DOMPrint [options] <XML file>\n\n"
               "This program invokes the DOM parser, and builds the DOM tree.\n"
  -            "It then traverses the DOM tree and prints the contents of the\n"
  -            "tree for the specified XML file.\n\n"
  +            "It then asks the DOMWriter to serialize the DOM tree \n"
               "Options:\n"
               "    -e          create entity reference nodes. Default is no expansion.\n"
  -            "    -u=xxx      Handle unrepresentable chars [fail | rep | ref*].\n"
               "    -v=xxx      Validation scheme [always | never | auto*].\n"
               "    -n          Enable namespace processing. Default is off.\n"
               "    -s          Enable schema processing. Default is off.\n"
               "    -f          Enable full schema constraint checking. Defaults is off.\n"
  -            "    -x=XXX      Use a particular encoding for output. Default is\n"
  +            "    -weol=xxx   Set the character sequence as end of line.\n"
  +            "    -wenc=XXX   Use a particular encoding for output. Default is\n"
               "                the same encoding as the input XML file. UTF-8 if\n"
               "                input XML file has not XML declaration.\n"
  +            "    -wcnf       canonical-form.                default off \n"
  +            "    -wfpp       format-pretty-print.           default off \n"
  +            "    -wnch       normalize-characters.          default off \n"
  +            "    -wval       validation.                    default off \n"
  +            "    -wscs       split-cdata-sections.          default on  \n"
  +			"    -wddc       discard-default-content.       default on  \n"
  +            "    -went       entity-reference-expansion.    default on  \n"
  +            "    -wwec       whitespace-in-element-content. default on  \n"
  +			"    -wfilter    use DOMPrintFilter.            default off \n"
  +			"    -wverify    verify the result from writeToString(). default off \n"
               "    -?          Show this help.\n\n"
               "  * = Default if not provided explicitly.\n\n"
               "The parser has intrinsic support for the following encodings:\n"
  @@ -290,8 +196,18 @@
             <<  endl;
   }
   
  +void setFeature(DOMWriter* ptr, const XMLCh* const featName, bool toState)
  +{
  +	try
  +	{
  +		ptr->setFeature(featName, toState);
  +	}
  +	catch(const DOMException&)
  +	{
  +		//absorb it here
  +	}
   
  -
  +}
   // ---------------------------------------------------------------------------
   //
   //  main
  @@ -376,35 +292,56 @@
           {
               gDoCreate = true;
           }
  -         else if (!strncmp(argV[parmInd], "-x=", 3)
  -              ||  !strncmp(argV[parmInd], "-X=", 3))
  +         else if (!strncmp(argV[parmInd], "-wenc=", 6))
           {
                // Get out the encoding name
  -             gEncodingName = XMLString::transcode( &(argV[parmInd][3]) );
  -             gEncodingNameisOnHeap = true;
  +             gEncodingName = XMLString::transcode( &(argV[parmInd][6]) );
  +        }			
  +         else if (!strncmp(argV[parmInd], "-weol=", 6))
  +        {
  +             // Get out the end of line
  +             gEndOfLineSequence = XMLString::transcode( &(argV[parmInd][6]) );
  +        }			
  +		 else if (!strcmp(argV[parmInd], "-wcnf"))
  +        {
  +            gCanonicalForm = !gCanonicalForm;
           }
  -         else if (!strncmp(argV[parmInd], "-u=", 3)
  -              ||  !strncmp(argV[parmInd], "-U=", 3))
  +         else if (!strcmp(argV[parmInd], "-wddc"))
           {
  -            const char* const parm = &argV[parmInd][3];
  -
  -            if (!strcmp(parm, "fail"))
  -                gUnRepFlags = XMLFormatter::UnRep_Fail;
  -            else if (!strcmp(parm, "rep"))
  -                gUnRepFlags = XMLFormatter::UnRep_Replace;
  -            else if (!strcmp(parm, "ref"))
  -                gUnRepFlags = XMLFormatter::UnRep_CharRef;
  -            else
  -            {
  -                cerr << "Unknown -u= value: " << parm << endl;
  -                XMLPlatformUtils::Terminate();
  -                return 2;
  -            }
  +            gDiscardDefaultContent = !gDiscardDefaultContent;
  +        }
  +         else if (!strcmp(argV[parmInd], "-went"))
  +        {
  +            gEntityReferenceExpansion = !gEntityReferenceExpansion;
  +        }
  +         else if (!strcmp(argV[parmInd], "-wfpp"))
  +        {
  +            gFormatPrettyPrint = !gFormatPrettyPrint;
  +        }
  +         else if (!strcmp(argV[parmInd], "-wnch"))
  +        {
  +            gNormalizeCharacters = !gNormalizeCharacters;
  +        }
  +         else if (!strcmp(argV[parmInd], "-wscs"))
  +        {
  +            gSplitCdataSections = !gSplitCdataSections;
  +        }
  +         else if (!strcmp(argV[parmInd], "-wval"))
  +        {
  +            gValidation = !gValidation;
  +        }
  +         else if (!strcmp(argV[parmInd], "-wwec"))
  +        {
  +            gWhitespaceInElementContent = !gWhitespaceInElementContent;
  +        }
  +         else if (!strcmp(argV[parmInd], "-wverify"))
  +        {
  +            gVerifyResult = !gVerifyResult;
  +        }
  +         else if (!strcmp(argV[parmInd], "-wfilter"))
  +        {
  +            gUseFilter = !gUseFilter;
           }
  -        //  else if (!strcmp(argV[parmInd], "-NoEscape"))
  -        // {
  -        //     gDoEscapes = false;
  -        // }
            else
           {
               cerr << "Unknown option '" << argV[parmInd]
  @@ -434,9 +371,10 @@
       parser->setDoNamespaces(gDoNamespaces);
       parser->setDoSchema(gDoSchema);
       parser->setValidationSchemaFullChecking(gSchemaFullChecking);
  +    parser->setCreateEntityReferenceNodes(gDoCreate);
  +
       DOMTreeErrorReporter *errReporter = new DOMTreeErrorReporter();
       parser->setErrorHandler(errReporter);
  -    parser->setCreateEntityReferenceNodes(gDoCreate);
   
       //
       //  Parse the XML file, catching any XML exceptions that might propogate
  @@ -455,7 +393,6 @@
           errorsOccured = true;
       }
   
  -
       catch (const DOMException& e)
       {
          cerr << "A DOM error occurred during parsing\n   DOMException code: "
  @@ -469,45 +406,62 @@
           errorsOccured = true;
       }
   
  -
       // If the parse was successful, output the document data from the DOM tree
       if (!errorsOccured && !errReporter->getSawErrors())
       {
  -        DOMNode *doc = parser->getDocument();
  -        DOMPrintFormatTarget* formatTarget = new DOMPrintFormatTarget();
  -
  -
  -        // Figure out the encoding that we want to use to write the document.
  -        //   If command line specified, use that,
  -        //   otherwise use utf-8.
  -        //
  +        DOMNode        *doc = parser->getDocument();
  +		DOMWriter      *theSerializer = new DOMWriterImpl();
   
  -        if (gEncodingName == 0)   // if no encoding specified on command line
  -        {
  -            static  const XMLCh utf_8[] = {chLatin_U, chLatin_T, chLatin_F, chDash, chDigit_8, 0};
  -            gEncodingName = utf_8;
  -        }
  -
  -
  -        //
  -        //  Create the output formatter and actually write the document HERE!
  -        //
           try
           {
  -            gFormatter = new XMLFormatter(gEncodingName, formatTarget,
  -                                          XMLFormatter::NoEscapes, gUnRepFlags);
  -
  -            //print out the XML Decl node first
  +			theSerializer->setNewLine(gEndOfLineSequence);
  +			theSerializer->setEncoding(gEncodingName);
   
  -            *gFormatter << gXMLDecl1 ;
  +			setFeature(theSerializer, DOMWriter::CanonicalForm,              gCanonicalForm);
  +			setFeature(theSerializer, DOMWriter::FormatPrettyPrint,          gFormatPrettyPrint);
  +			setFeature(theSerializer, DOMWriter::NormalizeCharacters,        gNormalizeCharacters);
  +			setFeature(theSerializer, DOMWriter::Validation,                 gValidation);
  +			setFeature(theSerializer, DOMWriter::SplitCdataSections,         gSplitCdataSections);
  +			setFeature(theSerializer, DOMWriter::DiscardDefaultContent,      gDiscardDefaultContent);
  +			setFeature(theSerializer, DOMWriter::Entities,                   gEntityReferenceExpansion);
  +			setFeature(theSerializer, DOMWriter::WhitespaceInElementContent, gWhitespaceInElementContent);
  +
  +			if (gUseFilter)
  +			{
  +				gFilter = new DOMPrintFilter(); 
  +				theSerializer->setFilter(gFilter);
  +			}
  +
  +			XMLCh* retString = theSerializer->writeToString(*doc);
  +			char *memString = XMLString::transcode(retString);		
  +			delete [] retString;      // release the memory allocated by writeToString()
  +
  +            cout<<memString;
  +			cout<<flush;
  +
  +			if (gVerifyResult)
  +			{
  +               /***
  +                  verify the output stream
  +				***/
  +				//MemBufInputSource* memBufIS = MemBufInputSource
  +				MemBufInputSource memBufIS((const XMLByte*)memString
  +                                         , strlen(memString)
  +                                         , "verifyResult"
  +										 , false);
  +
  +				parser->reset();
  +				parser->parse(memBufIS);
  +				DOMNode *doc2 = parser->getDocument();
  +				StdOutFormatTarget formatTarget;
  +				theSerializer->writeNode(&formatTarget, *doc2);
  +			}
  +			
  +			delete [] memString; // release the memory from the transcoder
   
  -            *gFormatter << gXMLDecl2 << gEncodingName;
  +			if (gUseFilter)
  +				delete gFilter;
   
  -            *gFormatter << gXMLDecl3;
  -
  -            cout << doc;
  -            *gFormatter << chLF; // add linefeed in requested output encoding
  -            cout << flush;
           }
           catch (XMLException& e)
           {
  @@ -517,8 +471,7 @@
               retval = 4;
           }
   
  -        delete formatTarget;
  -        delete gFormatter;
  +		delete theSerializer;
       }
       else
           retval = 4;
  @@ -538,8 +491,8 @@
       // And call the termination method
       XMLPlatformUtils::Terminate();
   
  -    if (gEncodingNameisOnHeap)
  -        delete (void *)gEncodingName;   // const problems.
  +	delete (void *)gEncodingName;        // const problems.
  +	delete (void *)gEndOfLineSequence;   // const problems.
   
       return retval;
   }
  @@ -547,247 +500,7 @@
   
   
   
  -// ---------------------------------------------------------------------------
  -//  ostream << DOM_Node
  -//
  -//  Stream out a DOM node, and, recursively, all of its children. This
  -//  function is the heart of writing a DOM tree out as XML source. Give it
  -//  a document node and it will do the whole thing.
  -// ---------------------------------------------------------------------------
  -ostream& operator<<(ostream& target, DOMNode *toWrite)
  -{
  -    // Get the name and value out for convenience
  -    const XMLCh *   nodeName = toWrite->getNodeName();
  -    const XMLCh *   nodeValue = toWrite->getNodeValue();
  -    unsigned long lent = XMLString::stringLen(nodeValue);
  -
  -    switch (toWrite->getNodeType())
  -    {
  -        case DOMNode::TEXT_NODE:
  -        {
  -            gFormatter->formatBuf(nodeValue,
  -                                  lent, XMLFormatter::CharEscapes);
  -            break;
  -        }
  -
  -
  -        case DOMNode::PROCESSING_INSTRUCTION_NODE :
  -        {
  -            *gFormatter << XMLFormatter::NoEscapes << gStartPI  << nodeName;
  -            if (lent > 0)
  -            {
  -                *gFormatter << chSpace << nodeValue;
  -            }
  -            *gFormatter << XMLFormatter::NoEscapes << gEndPI;
  -            break;
  -        }
  -
  -
  -        case DOMNode::DOCUMENT_NODE :
  -        {
  -
  -            DOMNode *child = toWrite->getFirstChild();
  -            while( child != 0)
  -            {
  -                target << child;
  -                // add linefeed in requested output encoding
  -                *gFormatter << chLF;
  -                target << flush;
  -
  -                child = child->getNextSibling();
  -            }
  -            break;
  -        }
  -
  -
  -        case DOMNode::ELEMENT_NODE :
  -        {
  -            // The name has to be representable without any escapes
  -            *gFormatter  << XMLFormatter::NoEscapes
  -                         << chOpenAngle << nodeName;
  -
  -            // Output the element start tag.
  -
  -            // Output any attributes on this element
  -            DOMNamedNodeMap *attributes = toWrite->getAttributes();
  -            int attrCount = attributes->getLength();
  -            for (int i = 0; i < attrCount; i++)
  -            {
  -                DOMNode  *attribute = attributes->item(i);
  -
  -                //
  -                //  Again the name has to be completely representable. But the
  -                //  attribute can have refs and requires the attribute style
  -                //  escaping.
  -                //
  -                *gFormatter  << XMLFormatter::NoEscapes
  -                             << chSpace << attribute->getNodeName()
  -                             << chEqual << chDoubleQuote
  -                             << XMLFormatter::AttrEscapes
  -                             << attribute->getNodeValue()
  -                             << XMLFormatter::NoEscapes
  -                             << chDoubleQuote;
  -            }
  -
  -            //
  -            //  Test for the presence of children, which includes both
  -            //  text content and nested elements.
  -            //
  -            DOMNode *child = toWrite->getFirstChild();
  -            if (child != 0)
  -            {
  -                // There are children. Close start-tag, and output children.
  -                // No escapes are legal here
  -                *gFormatter << XMLFormatter::NoEscapes << chCloseAngle;
  -
  -                while( child != 0)
  -                {
  -                    target << child;
  -                    child = child->getNextSibling();
  -                }
  -
  -                //
  -                // Done with children.  Output the end tag.
  -                //
  -                *gFormatter << XMLFormatter::NoEscapes << gEndElement
  -                            << nodeName << chCloseAngle;
  -            }
  -            else
  -            {
  -                //
  -                //  There were no children. Output the short form close of
  -                //  the element start tag, making it an empty-element tag.
  -                //
  -                *gFormatter << XMLFormatter::NoEscapes << chForwardSlash << chCloseAngle;
  -            }
  -            break;
  -        }
  -
  -
  -        case DOMNode::ENTITY_REFERENCE_NODE:
  -            {
  -#if 0
  -                DOMNode *child;
  -                for (child = toWrite->getFirstChild();
  -                child != 0;
  -                child = child->getNextSibling())
  -                {
  -                    target << child;
  -                }
  -#else
  -                //
  -                // Instead of printing the refernece tree
  -                // we'd output the actual text as it appeared in the xml file.
  -                // This would be the case when -e option was chosen
  -                //
  -                    *gFormatter << XMLFormatter::NoEscapes << chAmpersand
  -                        << nodeName << chSemiColon;
  -#endif
  -                break;
  -            }
  -
   
  -        case DOMNode::CDATA_SECTION_NODE:
  -            {
  -            *gFormatter << XMLFormatter::NoEscapes << gStartCDATA
  -                        << nodeValue << gEndCDATA;
  -            break;
  -        }
  -
  -
  -        case DOMNode::COMMENT_NODE:
  -        {
  -            *gFormatter << XMLFormatter::NoEscapes << gStartComment
  -                        << nodeValue << gEndComment;
  -            break;
  -        }
  -
  -
  -        case DOMNode::DOCUMENT_TYPE_NODE:
  -            {
  -            DOMDocumentType *doctype = (DOMDocumentType *)toWrite;;
  -
  -            *gFormatter << XMLFormatter::NoEscapes  << gStartDoctype
  -                        << nodeName;
  -
  -            const XMLCh  *id = doctype->getPublicId();
  -            if (id != 0 && *id != 0)
  -            {
  -                *gFormatter << XMLFormatter::NoEscapes << chSpace << gPublic
  -                    << id << chDoubleQuote;
  -            }
  -            id = doctype->getSystemId();
  -            if (id != 0 && *id != 0)
  -            {
  -                *gFormatter << XMLFormatter::NoEscapes << chSpace
  -                    << chDoubleQuote << id << chDoubleQuote;
  -            }
  -            id = doctype->getSystemId();
  -            if (id != 0 && *id != 0)
  -            {
  -                *gFormatter << XMLFormatter::NoEscapes << chSpace << gSystem
  -                    << id << chDoubleQuote;
  -            }
  -
  -            id = doctype->getInternalSubset();
  -            if (id != 0 && *id != 0)
  -                *gFormatter << XMLFormatter::NoEscapes << chOpenSquare
  -                << id << chCloseSquare;
  -
  -            *gFormatter << XMLFormatter::NoEscapes << chCloseAngle;
  -            break;
  -        }
  -
  -
  -        case DOMNode::ENTITY_NODE:
  -        {
  -            *gFormatter << XMLFormatter::NoEscapes << gStartEntity
  -                        << nodeName;
  -
  -            const XMLCh * id = ((DOMEntity *)toWrite)->getPublicId();
  -            if (id != 0)
  -                *gFormatter << XMLFormatter::NoEscapes << gPublic
  -                            << id << chDoubleQuote;
  -
  -            id = ((DOMEntity *)toWrite)->getSystemId();
  -            if (id != 0)
  -                *gFormatter << XMLFormatter::NoEscapes << gSystem
  -                            << id << chDoubleQuote;
  -
  -            id = ((DOMEntity *)toWrite)->getNotationName();
  -            if (id != 0)
  -                *gFormatter << XMLFormatter::NoEscapes << gNotation
  -                            << id << chDoubleQuote;
  -
  -            *gFormatter << XMLFormatter::NoEscapes << chCloseAngle << chLF;
  -
  -            break;
  -        }
  -
  -
  -
  -        default:
  -            cerr << "Unrecognized node type = "
  -                 << (long)toWrite->getNodeType() << endl;
  -    }
  -    return target;
  -}
  -
  -
  -
  -// ---------------------------------------------------------------------------
  -//  ostream << XMLCh *
  -//
  -//  Stream out a DOM string. Doing this requires that we first transcode
  -//  to char * form in the default code page for the system
  -// ---------------------------------------------------------------------------
  -ostream& operator<< (ostream& target, const XMLCh *s)
  -{
  -    char *p = XMLString::transcode(s);
  -    target << p;
  -    delete [] p;
  -    return target;
  -}
   
   
   
  
  
  

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