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 2001/08/02 19:10:29 UTC

cvs commit: xml-xerces/c/samples/SAXCount SAXCount.cpp SAXCountHandlers.cpp SAXCountHandlers.hpp

tng         01/08/02 10:10:29

  Modified:    c/samples/DOMCount DOMCount.cpp
               c/samples/IDOMCount IDOMCount.cpp
               c/samples/SAX2Count SAX2Count.cpp SAX2CountHandlers.cpp
                        SAX2CountHandlers.hpp
               c/samples/SAX2Print SAX2Print.cpp
               c/samples/SAXCount SAXCount.cpp SAXCountHandlers.cpp
                        SAXCountHandlers.hpp
  Log:
  Allow DOMCount/SAXCount/IDOMCount/SAX2Count to take a file that has a list of xml file as input.
  
  Revision  Changes    Path
  1.15      +100 -46   xml-xerces/c/samples/DOMCount/DOMCount.cpp
  
  Index: DOMCount.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/samples/DOMCount/DOMCount.cpp,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- DOMCount.cpp	2001/08/01 19:11:01	1.14
  +++ DOMCount.cpp	2001/08/02 17:10:28	1.15
  @@ -55,7 +55,7 @@
    */
   
   /*
  - * $Id: DOMCount.cpp,v 1.14 2001/08/01 19:11:01 tng Exp $
  + * $Id: DOMCount.cpp,v 1.15 2001/08/02 17:10:28 tng Exp $
    */
   
   // ---------------------------------------------------------------------------
  @@ -69,10 +69,10 @@
   #include "DOMCount.hpp"
   #include <string.h>
   #include <stdlib.h>
  +#include <fstream.h>
   
   
   
  -
   // ---------------------------------------------------------------------------
   //  This is a simple program which invokes the DOMParser to build a DOM
   //  tree for the specified input file. It then walks the tree and counts
  @@ -81,11 +81,12 @@
   void usage()
   {
       cout << "\nUsage:\n"
  -            "    DOMCount [options] <XML file>\n\n"
  +            "    DOMCount [options] <XML file> | List file>\n\n"
               "This program invokes the XML4C DOM parser, builds\n"
               "the DOM tree, and then prints the number of elements\n"
               "found in the input XML file.\n\n"
               "Options:\n"
  +            "    -l          Indicate the input file is a file that has a list of xml files.  Default: Input file is an XML file\n"
               "    -v=xxx      Validation scheme [always | never | auto*]\n"
               "    -n          Enable namespace processing. Defaults to off.\n"
               "    -s          Enable schema processing. Defaults to off.\n"
  @@ -122,6 +123,8 @@
       bool                     doNamespaces       = false;
       bool                     doSchema           = false;
       bool                     schemaFullChecking = false;
  +    bool                     doList = false;
  +    bool                     errorOccurred = false;
   
       // See if non validating dom parser configuration is requested.
       if ((argC == 2) && !strcmp(argV[1], "-?"))
  @@ -169,6 +172,11 @@
           {
               schemaFullChecking = true;
           }
  +         else if (!strcmp(argV[argInd], "-l")
  +              ||  !strcmp(argV[argInd], "-L"))
  +        {
  +            doList = true;
  +        }
            else
           {
               cerr << "Unknown option '" << argV[argInd]
  @@ -185,7 +193,6 @@
           usage();
           return 1;
       }
  -    xmlFile = argV[argInd];
   
       // Instantiate the DOM parser.
       DOMParser parser;
  @@ -203,58 +210,104 @@
       //  file. Catch any exceptions that might propogate out of it.
       //
       unsigned long duration;
  -    try
  -    {
  -        const unsigned long startMillis = XMLPlatformUtils::getCurrentMillis();
  -        parser.parse(xmlFile);
  -        const unsigned long endMillis = XMLPlatformUtils::getCurrentMillis();
  -        duration = endMillis - startMillis;
  -    }
   
  -    catch (const XMLException& toCatch)
  -    {
  -        cerr << "\nError during parsing: '" << xmlFile << "'\n"
  -             << "Exception message is:  \n"
  -             << StrX(toCatch.getMessage()) << "\n" << endl;
  -        return -1;
  -    }
  -    catch (const DOM_DOMException& toCatch)
  -    {
  -        cerr << "\nDOM Error during parsing: '" << xmlFile << "'\n"
  -             << "DOMException code is:  \n"
  -             << toCatch.code << "\n" << endl;
  -        XMLPlatformUtils::Terminate();
  -        return 4;
  -    }
  -    catch (...)
  -    {
  -       cerr << "\nUnexpected exception during parsing: '" << xmlFile << "'\n";
  -        XMLPlatformUtils::Terminate();
  -        return 4;
  -    }
  +    bool more = true;
  +    ifstream fin;
   
  -    //
  -    //  Extract the DOM tree, get the list of all the elements and report the
  -    //  length as the count of elements.
  -    //
  -    if (errorHandler.getSawErrors())
  -    {
  -        cout << "\nErrors occured, no output available\n" << endl;
  +    if (doList) {
  +
  +        // the input is a list file
  +        fin.open(argV[argInd]);
  +        if ( fin.is_open() == 0)
  +        {
  +            cerr << "Error opening list file: " << argV[argInd] << endl;
  +            XMLPlatformUtils::Terminate();
  +            return 1;
  +        }
       }
  -     else
  +
  +    while (more)
       {
  -        DOM_Document doc = parser.getDocument();
  -        unsigned int elementCount = doc.getElementsByTagName("*").getLength();
  +        char fURI[1000];
  +        if (doList) {
  +            if (! fin.eof() ) {
  +                fin.getline (fURI, sizeof(fURI));
  +                if (!*fURI)
  +                    continue;
  +                else
  +                    xmlFile = fURI;
  +            }
  +            else
  +                break;
  +        }
  +        else {
  +            xmlFile = argV[argInd];
  +            more = false;
  +        }
  +
  +        cerr << "==Parsing== " << xmlFile << endl;
  +
  +        //reset error count first
  +        errorHandler.resetErrors();
  +
  +        try
  +        {
  +            const unsigned long startMillis = XMLPlatformUtils::getCurrentMillis();
  +            parser.parse(xmlFile);
  +            const unsigned long endMillis = XMLPlatformUtils::getCurrentMillis();
  +            duration = endMillis - startMillis;
  +        }
  +
  +        catch (const XMLException& toCatch)
  +        {
  +            cerr << "\nError during parsing: '" << xmlFile << "'\n"
  +                 << "Exception message is:  \n"
  +                 << StrX(toCatch.getMessage()) << "\n" << endl;
  +            errorOccurred = true;
  +            continue;
  +        }
  +        catch (const DOM_DOMException& toCatch)
  +        {
  +            cerr << "\nDOM Error during parsing: '" << xmlFile << "'\n"
  +                 << "DOMException code is:  \n"
  +                 << toCatch.code << "\n" << endl;
  +            errorOccurred = true;
  +            continue;
  +        }
  +        catch (...)
  +        {
  +            cerr << "\nUnexpected exception during parsing: '" << xmlFile << "'\n";
  +            errorOccurred = true;
  +            continue;
  +        }
   
  -        // Print out the stats that we collected and time taken.
  -        cout << xmlFile << ": " << duration << " ms ("
  -             << elementCount << " elems)." << endl;
  +        //
  +        //  Extract the DOM tree, get the list of all the elements and report the
  +        //  length as the count of elements.
  +        //
  +        if (errorHandler.getSawErrors())
  +        {
  +            cout << "\nErrors occured, no output available\n" << endl;
  +        }
  +         else
  +        {
  +            DOM_Document doc = parser.getDocument();
  +            unsigned int elementCount = doc.getElementsByTagName("*").getLength();
  +
  +            // Print out the stats that we collected and time taken.
  +            cout << xmlFile << ": " << duration << " ms ("
  +                 << elementCount << " elems)." << endl;
  +        }
       }
   
       // And call the termination method
       XMLPlatformUtils::Terminate();
  +
  +    if (errorOccurred)
  +        return 4;
  +    else
  +        return 0;
   
  -    return 0;
   }
   
   
  @@ -300,4 +353,5 @@
   
   void DOMCountErrorHandler::resetErrors()
   {
  +    fSawErrors = false;
   }
  
  
  
  1.6       +102 -48   xml-xerces/c/samples/IDOMCount/IDOMCount.cpp
  
  Index: IDOMCount.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/samples/IDOMCount/IDOMCount.cpp,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- IDOMCount.cpp	2001/08/01 19:11:01	1.5
  +++ IDOMCount.cpp	2001/08/02 17:10:29	1.6
  @@ -55,7 +55,7 @@
    */
   
   /*
  - * $Id: IDOMCount.cpp,v 1.5 2001/08/01 19:11:01 tng Exp $
  + * $Id: IDOMCount.cpp,v 1.6 2001/08/02 17:10:29 tng Exp $
    */
   
   // ---------------------------------------------------------------------------
  @@ -70,6 +70,7 @@
   #include "IDOMCount.hpp"
   #include <string.h>
   #include <stdlib.h>
  +#include <fstream.h>
   
   
   
  @@ -82,11 +83,12 @@
   static void usage()
   {
       cout << "\nUsage:\n"
  -            "    IDOMCount [options] <XML file>\n\n"
  +            "    IDOMCount [options] <XML file> | List file>\n\n"
               "This program invokes the XML4C DOM parser, builds\n"
               "the DOM tree, and then prints the number of elements\n"
               "found in the input XML file.\n\n"
               "Options:\n"
  +            "    -l          Indicate the input file is a file that has a list of xml files.  Default: Input file is an XML file\n"
               "    -v=xxx      Validation scheme [always | never | auto*]\n"
               "    -n          Enable namespace processing. Defaults to off.\n"
               "    -s          Enable schema processing. Defaults to off.\n"
  @@ -155,6 +157,8 @@
       bool                      doNamespaces       = false;
       bool                      doSchema           = false;
       bool                      schemaFullChecking = false;
  +    bool                      doList = false;
  +    bool                      errorOccurred = false;
   
       // See if non validating dom parser configuration is requested.
       if ((argC == 2) && !strcmp(argV[1], "-?"))
  @@ -202,6 +206,11 @@
           {
               schemaFullChecking = true;
           }
  +         else if (!strcmp(argV[argInd], "-l")
  +              ||  !strcmp(argV[argInd], "-L"))
  +        {
  +            doList = true;
  +        }
            else
           {
               cerr << "Unknown option '" << argV[argInd]
  @@ -218,7 +227,6 @@
           usage();
           return 1;
       }
  -    xmlFile = argV[argInd];
   
       // Instantiate the DOM parser.
       IDOMParser parser;
  @@ -236,60 +244,105 @@
       //  file. Catch any exceptions that might propogate out of it.
       //
       unsigned long duration;
  -    try
  -    {
  -        const unsigned long startMillis = XMLPlatformUtils::getCurrentMillis();
  -        parser.parse(xmlFile);
  -        const unsigned long endMillis = XMLPlatformUtils::getCurrentMillis();
  -        duration = endMillis - startMillis;
  -    }
   
  -    catch (const XMLException& toCatch)
  -    {
  -        cerr << "\nError during parsing: '" << xmlFile << "'\n"
  -             << "Exception message is:  \n"
  -             << StrX(toCatch.getMessage()) << "\n" << endl;
  -        return -1;
  -    }
  -    catch (const IDOM_DOMException& toCatch)
  -    {
  -        cerr << "\nDOM Error during parsing: '" << xmlFile << "'\n"
  -             << "DOMException code is:  \n"
  -             << toCatch.code << "\n" << endl;
  -        XMLPlatformUtils::Terminate();
  -        return 4;
  -    }
  -    catch (...)
  -    {
  -       cerr << "\nUnexpected exception during parsing: '" << xmlFile << "'\n";
  -        XMLPlatformUtils::Terminate();
  -        return 4;
  -    }
  +    bool more = true;
  +    ifstream fin;
   
  -    //
  -    //  Extract the DOM tree, get the list of all the elements and report the
  -    //  length as the count of elements.
  -    //
  -    if (errorHandler.getSawErrors())
  -    {
  -        cout << "\nErrors occured, no output available\n" << endl;
  +    if (doList) {
  +
  +        // the input is a list file
  +        fin.open(argV[argInd]);
  +        if ( fin.is_open() == 0)
  +        {
  +            cerr << "Error opening list file: " << argV[argInd] << endl;
  +            XMLPlatformUtils::Terminate();
  +            return 1;
  +        }
       }
  -     else
  +
  +    while (more)
       {
  -        IDOM_Document *doc = parser.getDocument();
  -        unsigned int elementCount = 0;
  -        if (doc)
  -            elementCount = countChildElements((IDOM_Node*)doc->getDocumentElement());
  -
  -        // Print out the stats that we collected and time taken.
  -        cout << xmlFile << ": " << duration << " ms ("
  -             << elementCount << " elems)." << endl;
  +        char fURI[1000];
  +        if (doList) {
  +            if (! fin.eof() ) {
  +                fin.getline (fURI, sizeof(fURI));
  +                if (!*fURI)
  +                    continue;
  +                else
  +                    xmlFile = fURI;
  +            }
  +            else
  +                break;
  +        }
  +        else {
  +            xmlFile = argV[argInd];
  +            more = false;
  +        }
  +
  +        cerr << "==Parsing== " << xmlFile << endl;
  +
  +        //reset error count first
  +        errorHandler.resetErrors();
  +
  +        try
  +        {
  +            const unsigned long startMillis = XMLPlatformUtils::getCurrentMillis();
  +            parser.parse(xmlFile);
  +            const unsigned long endMillis = XMLPlatformUtils::getCurrentMillis();
  +            duration = endMillis - startMillis;
  +        }
  +
  +        catch (const XMLException& toCatch)
  +        {
  +            cerr << "\nError during parsing: '" << xmlFile << "'\n"
  +                 << "Exception message is:  \n"
  +                 << StrX(toCatch.getMessage()) << "\n" << endl;
  +            errorOccurred = true;
  +            continue;
  +        }
  +        catch (const IDOM_DOMException& toCatch)
  +        {
  +            cerr << "\nDOM Error during parsing: '" << xmlFile << "'\n"
  +                 << "DOMException code is:  \n"
  +                 << toCatch.code << "\n" << endl;
  +            errorOccurred = true;
  +            continue;
  +        }
  +        catch (...)
  +        {
  +            cerr << "\nUnexpected exception during parsing: '" << xmlFile << "'\n";
  +            errorOccurred = true;
  +            continue;
  +        }
  +
  +        //
  +        //  Extract the DOM tree, get the list of all the elements and report the
  +        //  length as the count of elements.
  +        //
  +        if (errorHandler.getSawErrors())
  +        {
  +            cout << "\nErrors occured, no output available\n" << endl;
  +        }
  +         else
  +        {
  +            IDOM_Document *doc = parser.getDocument();
  +            unsigned int elementCount = 0;
  +            if (doc)
  +                elementCount = countChildElements((IDOM_Node*)doc->getDocumentElement());
  +
  +            // Print out the stats that we collected and time taken.
  +            cout << xmlFile << ": " << duration << " ms ("
  +                 << elementCount << " elems)." << endl;
  +        }
       }
   
       // And call the termination method
       XMLPlatformUtils::Terminate();
   
  -    return 0;
  +    if (errorOccurred)
  +        return 4;
  +    else
  +        return 0;
   }
   
   
  @@ -338,4 +391,5 @@
   
   void DOMCountErrorHandler::resetErrors()
   {
  +    fSawErrors = false;
   }
  
  
  
  1.7       +104 -47   xml-xerces/c/samples/SAX2Count/SAX2Count.cpp
  
  Index: SAX2Count.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/samples/SAX2Count/SAX2Count.cpp,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- SAX2Count.cpp	2001/08/01 19:11:01	1.6
  +++ SAX2Count.cpp	2001/08/02 17:10:29	1.7
  @@ -56,6 +56,9 @@
   
   /*
   * $Log: SAX2Count.cpp,v $
  +* Revision 1.7  2001/08/02 17:10:29  tng
  +* Allow DOMCount/SAXCount/IDOMCount/SAX2Count to take a file that has a list of xml file as input.
  +*
   * Revision 1.6  2001/08/01 19:11:01  tng
   * Add full schema constraint checking flag to the samples and the parser.
   *
  @@ -85,6 +88,7 @@
   #include <util/PlatformUtils.hpp>
   #include <sax2/SAX2XMLReader.hpp>
   #include <sax2/XMLReaderFactory.hpp>
  +#include <fstream.h>
   
   // ---------------------------------------------------------------------------
   //  Local helper methods
  @@ -92,11 +96,12 @@
   void usage()
   {
       cout << "\nUsage:\n"
  -            "    SAX2Count [options] <XML file>\n\n"
  +            "    SAX2Count [options] <XML file> | List file>\n\n"
               "Options:\n"
  +            "    -l          Indicate the input file is a file that has a list of xml files.  Default: Input file is an XML file\n"
               "    -v=xxx      Validation scheme [always | never | auto*]\n"
               "    -n          Disable namespace processing. Defaults to on.\n"
  -            "    -s          Disable schema processing. Defaults to on.\n\n"
  +            "    -s          Disable schema processing. Defaults to on.\n"
               "    -f          Enable full schema constraint checking processing. Defaults to off.\n\n"
               "This program prints the number of elements, attributes,\n"
               "white spaces and other non-white space characters in the "
  @@ -137,6 +142,8 @@
       bool                         doNamespaces = true;
       bool                         doSchema = true;
       bool                         schemaFullChecking = false;
  +    bool                         doList = false;
  +    bool                         errorOccurred = false;
   
       // See if non validating dom parser configuration is requested.
       if ((argC == 2) && !strcmp(argV[1], "-?"))
  @@ -185,6 +192,11 @@
           {
               schemaFullChecking = true;
           }
  +         else if (!strcmp(argV[argInd], "-l")
  +              ||  !strcmp(argV[argInd], "-L"))
  +        {
  +            doList = true;
  +        }
           else
           {
               cerr << "Unknown option '" << argV[argInd]
  @@ -202,30 +214,30 @@
           XMLPlatformUtils::Terminate();
           return 1;
       }
  -    xmlFile = argV[argInd];
   
       //
       //  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();
  -	parser->setFeature(XMLString::transcode("http://xml.org/sax/features/namespaces"), doNamespaces);
  -	parser->setFeature(XMLString::transcode("http://apache.org/xml/features/validation/schema"), doSchema);
  -	parser->setFeature(XMLString::transcode("http://apache.org/xml/features/validation/schema-full-checking"), schemaFullChecking);
  -	if (valScheme == SAX2XMLReader::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);
  -	}
  +    parser->setFeature(XMLString::transcode("http://xml.org/sax/features/namespaces"), doNamespaces);
  +    parser->setFeature(XMLString::transcode("http://apache.org/xml/features/validation/schema"), doSchema);
  +    parser->setFeature(XMLString::transcode("http://apache.org/xml/features/validation/schema-full-checking"), schemaFullChecking);
  +
  +    if (valScheme == SAX2XMLReader::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 == SAX2XMLReader::Val_Never)
  -	{
  -	  parser->setFeature(XMLString::transcode("http://xml.org/sax/features/validation"), false);
  -	}
  -	if (valScheme == SAX2XMLReader::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);
  -	}
  +    {
  +        parser->setFeature(XMLString::transcode("http://xml.org/sax/features/validation"), false);
  +    }
  +    if (valScheme == SAX2XMLReader::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 our SAX handler object and install it on the parser, as the
  @@ -240,44 +252,89 @@
       //  file. Catch any exceptions that might propogate out of it.
       //
       unsigned long duration;
  -    try
  -    {
  -        const unsigned long startMillis = XMLPlatformUtils::getCurrentMillis();
  -        parser->parse(xmlFile);
  -        const unsigned long endMillis = XMLPlatformUtils::getCurrentMillis();
  -        duration = endMillis - startMillis;
  -    }
   
  -    catch (const XMLException& e)
  -    {
  -        cerr << "\nError during parsing: '" << xmlFile << "'\n"
  -            << "Exception message is:  \n"
  -            << StrX(e.getMessage()) << "\n" << endl;
  -        XMLPlatformUtils::Terminate();
  -        return 4;
  +    bool more = true;
  +    ifstream fin;
  +
  +    if (doList) {
  +
  +        // the input is a list file
  +        fin.open(argV[argInd]);
  +        if ( fin.is_open() == 0)
  +        {
  +            cerr << "Error opening list file: " << argV[argInd] << endl;
  +            XMLPlatformUtils::Terminate();
  +            return 1;
  +        }
       }
   
  -    catch (...)
  +    while (more)
       {
  -        cerr << "\nUnexpected exception during parsing: '" << xmlFile << "'\n";
  -        XMLPlatformUtils::Terminate();
  -        return 4;
  -    }
  +        char fURI[1000];
  +        if (doList) {
  +            if (! fin.eof() ) {
  +                fin.getline (fURI, sizeof(fURI));
  +                if (!*fURI)
  +                    continue;
  +                else
  +                    xmlFile = fURI;
  +            }
  +            else
  +                break;
  +        }
  +        else {
  +            xmlFile = argV[argInd];
  +            more = false;
  +        }
   
  +        cerr << "==Parsing== " << xmlFile << endl;
   
  -    // Print out the stats that we collected and time taken
  -    if (!handler.getSawErrors())
  -    {
  -        cout << xmlFile << ": " << duration << " ms ("
  -            << handler.getElementCount() << " elems, "
  -            << handler.getAttrCount() << " attrs, "
  -            << handler.getSpaceCount() << " spaces, "
  -            << handler.getCharacterCount() << " chars)" << endl;
  +        //reset error count first
  +        handler.resetErrors();
  +
  +        try
  +        {
  +            const unsigned long startMillis = XMLPlatformUtils::getCurrentMillis();
  +            parser->parse(xmlFile);
  +            const unsigned long endMillis = XMLPlatformUtils::getCurrentMillis();
  +            duration = endMillis - startMillis;
  +        }
  +
  +        catch (const XMLException& e)
  +        {
  +            cerr << "\nError during parsing: '" << xmlFile << "'\n"
  +                << "Exception message is:  \n"
  +                << StrX(e.getMessage()) << "\n" << endl;
  +            errorOccurred = true;
  +            continue;
  +        }
  +
  +        catch (...)
  +        {
  +            cerr << "\nUnexpected exception during parsing: '" << xmlFile << "'\n";
  +            errorOccurred = true;
  +            continue;
  +        }
  +
  +
  +        // Print out the stats that we collected and time taken
  +        if (!handler.getSawErrors())
  +        {
  +            cout << xmlFile << ": " << duration << " ms ("
  +                << handler.getElementCount() << " elems, "
  +                << handler.getAttrCount() << " attrs, "
  +                << handler.getSpaceCount() << " spaces, "
  +                << handler.getCharacterCount() << " chars)" << endl;
  +        }
       }
   
       // And call the termination method
       XMLPlatformUtils::Terminate();
  +
  +    if (errorOccurred)
  +        return 4;
  +    else
  +        return 0;
   
  -    return 0;
   }
   
  
  
  
  1.3       +8 -0      xml-xerces/c/samples/SAX2Count/SAX2CountHandlers.cpp
  
  Index: SAX2CountHandlers.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/samples/SAX2Count/SAX2CountHandlers.cpp,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SAX2CountHandlers.cpp	2000/08/09 22:40:15	1.2
  +++ SAX2CountHandlers.cpp	2001/08/02 17:10:29	1.3
  @@ -56,6 +56,9 @@
   
   /*
    * $Log: SAX2CountHandlers.cpp,v $
  + * Revision 1.3  2001/08/02 17:10:29  tng
  + * Allow DOMCount/SAXCount/IDOMCount/SAX2Count to take a file that has a list of xml file as input.
  + *
    * Revision 1.2  2000/08/09 22:40:15  jpolast
    * updates for changes to sax2 core functionality.
    *
  @@ -152,4 +155,9 @@
   		 << ", line " << e.getLineNumber()
   		 << ", char " << e.getColumnNumber()
            << "\n  Message: " << StrX(e.getMessage()) << endl;
  +}
  +
  +void SAX2CountHandlers::resetErrors()
  +{
  +    fSawErrors = false;
   }
  
  
  
  1.3       +17 -13    xml-xerces/c/samples/SAX2Count/SAX2CountHandlers.hpp
  
  Index: SAX2CountHandlers.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/samples/SAX2Count/SAX2CountHandlers.hpp,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SAX2CountHandlers.hpp	2000/08/09 22:40:15	1.2
  +++ SAX2CountHandlers.hpp	2001/08/02 17:10:29	1.3
  @@ -1,37 +1,37 @@
   /*
    * 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. 
  - * 
  + *    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:  
  + *    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 
  + *    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
  @@ -45,7 +45,7 @@
    * 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
  @@ -56,13 +56,16 @@
   
   /*
    * $Log: SAX2CountHandlers.hpp,v $
  + * Revision 1.3  2001/08/02 17:10:29  tng
  + * Allow DOMCount/SAXCount/IDOMCount/SAX2Count to take a file that has a list of xml file as input.
  + *
    * Revision 1.2  2000/08/09 22:40:15  jpolast
    * updates for changes to sax2 core functionality.
    *
    * Revision 1.1  2000/08/08 17:17:21  jpolast
    * initial checkin of SAX2Count
  + *
    *
  - * 
    */
   
   
  @@ -126,6 +129,7 @@
   	void warning(const SAXParseException& exception);
       void error(const SAXParseException& exception);
       void fatalError(const SAXParseException& exception);
  +    void resetErrors();
   
   
   private:
  
  
  
  1.4       +4 -1      xml-xerces/c/samples/SAX2Print/SAX2Print.cpp
  
  Index: SAX2Print.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/samples/SAX2Print/SAX2Print.cpp,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- SAX2Print.cpp	2001/08/01 19:11:01	1.3
  +++ SAX2Print.cpp	2001/08/02 17:10:29	1.4
  @@ -56,6 +56,9 @@
   
   /*
    * $Log: SAX2Print.cpp,v $
  + * Revision 1.4  2001/08/02 17:10:29  tng
  + * Allow DOMCount/SAXCount/IDOMCount/SAX2Count to take a file that has a list of xml file as input.
  + *
    * Revision 1.3  2001/08/01 19:11:01  tng
    * Add full schema constraint checking flag to the samples and the parser.
    *
  @@ -121,7 +124,7 @@
                "    -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"
  -             "    -s          Disable schema processing. Defaults to on.\n\n"
  +             "    -s          Disable schema processing. Defaults to on.\n"
                "    -f          Enable full schema constraint checking processing. Defaults to off.\n\n"
                "    -?          Show this help\n\n"
                "  * = Default if not provided explicitly\n\n"
  
  
  
  1.13      +88 -34    xml-xerces/c/samples/SAXCount/SAXCount.cpp
  
  Index: SAXCount.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/samples/SAXCount/SAXCount.cpp,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- SAXCount.cpp	2001/08/01 19:11:01	1.12
  +++ SAXCount.cpp	2001/08/02 17:10:29	1.13
  @@ -56,6 +56,9 @@
   
   /*
   * $Log: SAXCount.cpp,v $
  +* Revision 1.13  2001/08/02 17:10:29  tng
  +* Allow DOMCount/SAXCount/IDOMCount/SAX2Count to take a file that has a list of xml file as input.
  +*
   * Revision 1.12  2001/08/01 19:11:01  tng
   * Add full schema constraint checking flag to the samples and the parser.
   *
  @@ -111,7 +114,7 @@
   //  Includes
   // ---------------------------------------------------------------------------
   #include "SAXCount.hpp"
  -
  +#include <fstream.h>
   
   // ---------------------------------------------------------------------------
   //  Local helper methods
  @@ -119,8 +122,9 @@
   void usage()
   {
       cout << "\nUsage:\n"
  -            "    SAXCount [options] <XML file>\n\n"
  +            "    SAXCount [options] <XML file> | List file>\n\n"
               "Options:\n"
  +            "    -l          Indicate the input file is a file that has a list of xml files.  Default: Input file is an XML file\n"
               "    -v=xxx      Validation scheme [always | never | auto*]\n"
               "    -n          Enable namespace processing. Defaults to off.\n"
               "    -s          Enable schema processing. Defaults to off.\n"
  @@ -164,6 +168,8 @@
       bool                     doNamespaces       = false;
       bool                     doSchema           = false;
       bool                     schemaFullChecking = false;
  +    bool                     doList = false;
  +    bool                     errorOccurred = false;
   
   
       int argInd;
  @@ -205,6 +211,11 @@
           {
               schemaFullChecking = true;
           }
  +         else if (!strcmp(argV[argInd], "-l")
  +              ||  !strcmp(argV[argInd], "-L"))
  +        {
  +            doList = true;
  +        }
           else
           {
               cerr << "Unknown option '" << argV[argInd]
  @@ -223,36 +234,75 @@
           return 1;
       }
   
  +    //
  +    //  Create a SAX parser object. Then, according to what we were told on
  +    //  the command line, set it to validate or not.
  +    //
  +    SAXParser parser;
  +
  +    parser.setValidationScheme(valScheme);
  +    parser.setDoNamespaces(doNamespaces);
  +    parser.setDoSchema(doSchema);
  +    parser.setValidationSchemaFullChecking(schemaFullChecking);
   
  -    for (; argInd < argC; argInd++)
  +    //
  +    //  Create our SAX handler object and install it on the parser, as the
  +    //  document and error handler.
  +    //
  +    SAXCountHandlers handler;
  +    parser.setDocumentHandler(&handler);
  +    parser.setErrorHandler(&handler);
  +
  +
  +    //
  +    //  Get the starting time and kick off the parse of the indicated
  +    //  file. Catch any exceptions that might propogate out of it.
  +    //
  +    unsigned long duration;
  +
  +    ifstream fin;
  +
  +    if (doList) {
  +
  +        // the input is a list file
  +        fin.open(argV[argInd]);
  +        if ( fin.is_open() == 0)
  +        {
  +            cerr << "Error opening list file: " << argV[argInd] << endl;
  +            XMLPlatformUtils::Terminate();
  +            return 1;
  +        }
  +    }
  +
  +    while (true)
       {
  -        xmlFile = argV[argInd];
  +        char fURI[1000];
  +        if (doList) {
  +            if (! fin.eof() ) {
  +                fin.getline (fURI, sizeof(fURI));
  +                if (!*fURI)
  +                    continue;
  +                else
  +                    xmlFile = fURI;
  +            }
  +            else
  +                break;
  +        }
  +        else {
  +            if (argInd < argC)
  +            {
  +                 xmlFile = argV[argInd];
  +                 argInd++;
  +            }
  +            else
  +                break;
  +        }
  +
  +        cerr << "==Parsing== " << xmlFile << endl;
   
  -        //
  -        //  Create a SAX parser object. Then, according to what we were told on
  -        //  the command line, set it to validate or not.
  -        //
  -        SAXParser parser;
  -
  -        parser.setValidationScheme(valScheme);
  -        parser.setDoNamespaces(doNamespaces);
  -        parser.setDoSchema(doSchema);
  -        parser.setValidationSchemaFullChecking(schemaFullChecking);
  -
  -        //
  -        //  Create our SAX handler object and install it on the parser, as the
  -        //  document and error handler.
  -        //
  -        SAXCountHandlers handler;
  -        parser.setDocumentHandler(&handler);
  -        parser.setErrorHandler(&handler);
  -
  -
  -        //
  -        //  Get the starting time and kick off the parse of the indicated
  -        //  file. Catch any exceptions that might propogate out of it.
  -        //
  -        unsigned long duration;
  +        //reset error count first
  +        handler.resetErrors();
  +
           try
           {
               const unsigned long startMillis = XMLPlatformUtils::getCurrentMillis();
  @@ -266,15 +316,15 @@
               cerr << "\nError during parsing: '" << xmlFile << "'\n"
                   << "Exception message is:  \n"
                   << StrX(e.getMessage()) << "\n" << endl;
  -            XMLPlatformUtils::Terminate();
  -            return 4;
  +            errorOccurred = true;
  +            continue;
           }
   
           catch (...)
           {
               cerr << "\nUnexpected exception during parsing: '" << xmlFile << "'\n";
  -            XMLPlatformUtils::Terminate();
  -            return 4;
  +            errorOccurred = true;
  +            continue;
           }
   
   
  @@ -291,7 +341,11 @@
   
       // And call the termination method
       XMLPlatformUtils::Terminate();
  +
  +    if (errorOccurred)
  +        return 4;
  +    else
  +        return 0;
   
  -    return 0;
   }
   
  
  
  
  1.4       +10 -0     xml-xerces/c/samples/SAXCount/SAXCountHandlers.cpp
  
  Index: SAXCountHandlers.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/samples/SAXCount/SAXCountHandlers.cpp,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- SAXCountHandlers.cpp	2000/03/02 19:53:47	1.3
  +++ SAXCountHandlers.cpp	2001/08/02 17:10:29	1.4
  @@ -56,6 +56,9 @@
   
   /*
    * $Log: SAXCountHandlers.cpp,v $
  + * Revision 1.4  2001/08/02 17:10:29  tng
  + * Allow DOMCount/SAXCount/IDOMCount/SAX2Count to take a file that has a list of xml file as input.
  + *
    * Revision 1.3  2000/03/02 19:53:47  roddey
    * This checkin includes many changes done while waiting for the
    * 1.1.0 code to be finished. I can't list them all here, but a list is
  @@ -158,4 +161,9 @@
   		 << ", line " << e.getLineNumber()
   		 << ", char " << e.getColumnNumber()
            << "\n  Message: " << StrX(e.getMessage()) << endl;
  +}
  +
  +void SAXCountHandlers::resetErrors()
  +{
  +    fSawErrors = false;
   }
  
  
  
  1.4       +18 -12    xml-xerces/c/samples/SAXCount/SAXCountHandlers.hpp
  
  Index: SAXCountHandlers.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/samples/SAXCount/SAXCountHandlers.hpp,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- SAXCountHandlers.hpp	2000/03/02 19:53:47	1.3
  +++ SAXCountHandlers.hpp	2001/08/02 17:10:29	1.4
  @@ -1,37 +1,37 @@
   /*
    * 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. 
  - * 
  + *    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:  
  + *    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 
  + *    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
  @@ -45,7 +45,7 @@
    * 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
  @@ -56,6 +56,9 @@
   
   /*
    * $Log: SAXCountHandlers.hpp,v $
  + * Revision 1.4  2001/08/02 17:10:29  tng
  + * Allow DOMCount/SAXCount/IDOMCount/SAX2Count to take a file that has a list of xml file as input.
  + *
    * Revision 1.3  2000/03/02 19:53:47  roddey
    * This checkin includes many changes done while waiting for the
    * 1.1.0 code to be finished. I can't list them all here, but a list is
  @@ -134,6 +137,7 @@
   	void warning(const SAXParseException& exception);
       void error(const SAXParseException& exception);
       void fatalError(const SAXParseException& exception);
  +    void resetErrors();
   
   
   private:
  
  
  

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