source: NonGTP/Xerces/xerces/samples/SAXCount/SAXCountHandlers.cpp @ 358

Revision 358, 4.4 KB checked in by bittner, 19 years ago (diff)

xerces added

Line 
1/*
2 * Copyright 1999-2000,2004 The Apache Software Foundation.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17/*
18 * $Log: SAXCountHandlers.cpp,v $
19 * Revision 1.7  2004/09/08 13:55:33  peiyongz
20 * Apache License Version 2.0
21 *
22 * Revision 1.6  2003/05/30 09:36:36  gareth
23 * Use new macros for iostream.h and std:: issues.
24 *
25 * Revision 1.5  2002/02/01 22:41:07  peiyongz
26 * sane_include
27 *
28 * Revision 1.4  2001/08/02 17:10:29  tng
29 * Allow DOMCount/SAXCount/IDOMCount/SAX2Count to take a file that has a list of xml file as input.
30 *
31 * Revision 1.3  2000/03/02 19:53:47  roddey
32 * This checkin includes many changes done while waiting for the
33 * 1.1.0 code to be finished. I can't list them all here, but a list is
34 * available elsewhere.
35 *
36 * Revision 1.2  2000/02/06 07:47:23  rahulj
37 * Year 2K copyright swat.
38 *
39 * Revision 1.1.1.1  1999/11/09 01:09:31  twl
40 * Initial checkin
41 *
42 * Revision 1.8  1999/11/08 20:43:40  rahul
43 * Swat for adding in Product name and CVS comment log variable.
44 *
45 */
46
47// ---------------------------------------------------------------------------
48//  Includes
49// ---------------------------------------------------------------------------
50#include "SAXCount.hpp"
51#include <xercesc/sax/AttributeList.hpp>
52#include <xercesc/sax/SAXParseException.hpp>
53#include <xercesc/sax/SAXException.hpp>
54
55
56
57// ---------------------------------------------------------------------------
58//  SAXCountHandlers: Constructors and Destructor
59// ---------------------------------------------------------------------------
60SAXCountHandlers::SAXCountHandlers() :
61
62    fElementCount(0)
63    , fAttrCount(0)
64    , fCharacterCount(0)
65    , fSpaceCount(0)
66    , fSawErrors(false)
67{
68}
69
70SAXCountHandlers::~SAXCountHandlers()
71{
72}
73
74
75// ---------------------------------------------------------------------------
76//  SAXCountHandlers: Implementation of the SAX DocumentHandler interface
77// ---------------------------------------------------------------------------
78void SAXCountHandlers::startElement(const   XMLCh* const    name
79                                    ,       AttributeList&  attributes)
80{
81    fElementCount++;
82    fAttrCount += attributes.getLength();
83}
84
85void SAXCountHandlers::characters(  const   XMLCh* const    chars
86                                                                    , const unsigned int    length)
87{
88    fCharacterCount += length;
89}
90
91void SAXCountHandlers::ignorableWhitespace( const   XMLCh* const chars
92                                                                                    , const unsigned int length)
93{
94    fSpaceCount += length;
95}
96
97void SAXCountHandlers::resetDocument()
98{
99    fAttrCount = 0;
100    fCharacterCount = 0;
101    fElementCount = 0;
102    fSpaceCount = 0;
103}
104
105
106// ---------------------------------------------------------------------------
107//  SAXCountHandlers: Overrides of the SAX ErrorHandler interface
108// ---------------------------------------------------------------------------
109void SAXCountHandlers::error(const SAXParseException& e)
110{
111    fSawErrors = true;
112    XERCES_STD_QUALIFIER cerr << "\nError at file " << StrX(e.getSystemId())
113                 << ", line " << e.getLineNumber()
114                 << ", char " << e.getColumnNumber()
115         << "\n  Message: " << StrX(e.getMessage()) << XERCES_STD_QUALIFIER endl;
116}
117
118void SAXCountHandlers::fatalError(const SAXParseException& e)
119{
120    fSawErrors = true;
121    XERCES_STD_QUALIFIER cerr << "\nFatal Error at file " << StrX(e.getSystemId())
122                 << ", line " << e.getLineNumber()
123                 << ", char " << e.getColumnNumber()
124         << "\n  Message: " << StrX(e.getMessage()) << XERCES_STD_QUALIFIER endl;
125}
126
127void SAXCountHandlers::warning(const SAXParseException& e)
128{
129    XERCES_STD_QUALIFIER cerr << "\nWarning at file " << StrX(e.getSystemId())
130                 << ", line " << e.getLineNumber()
131                 << ", char " << e.getColumnNumber()
132         << "\n  Message: " << StrX(e.getMessage()) << XERCES_STD_QUALIFIER endl;
133}
134
135void SAXCountHandlers::resetErrors()
136{
137    fSawErrors = false;
138}
Note: See TracBrowser for help on using the repository browser.