source: icXML/icXML-devel/samples/src/SAX2Count/SAX2CountHandlers.cpp @ 2726

Last change on this file since 2726 was 2726, checked in by cameron, 7 years ago

Add original Xerces tests and samples directories

File size: 3.8 KB
Line 
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements.  See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License.  You may obtain a copy of the License at
8 *
9 *      http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18/*
19 * $Id: SAX2CountHandlers.cpp 557282 2007-07-18 14:54:15Z amassari $
20 */
21
22// ---------------------------------------------------------------------------
23//  Includes
24// ---------------------------------------------------------------------------
25#include "SAX2Count.hpp"
26#include <xercesc/sax2/Attributes.hpp>
27#include <xercesc/sax/SAXParseException.hpp>
28#include <xercesc/sax/SAXException.hpp>
29
30
31
32// ---------------------------------------------------------------------------
33//  SAX2CountHandlers: Constructors and Destructor
34// ---------------------------------------------------------------------------
35SAX2CountHandlers::SAX2CountHandlers() :
36
37    fAttrCount(0)
38    , fCharacterCount(0)
39    , fElementCount(0)
40    , fSpaceCount(0)
41    , fSawErrors(false)
42{
43}
44
45SAX2CountHandlers::~SAX2CountHandlers()
46{
47}
48
49// ---------------------------------------------------------------------------
50//  SAX2CountHandlers: Implementation of the SAX DocumentHandler interface
51// ---------------------------------------------------------------------------
52void SAX2CountHandlers::startElement(const XMLCh* const /* uri */
53                                   , const XMLCh* const /* localname */
54                                   , const XMLCh* const /* qname */
55                                   , const Attributes& attrs)
56{
57    fElementCount++;
58    fAttrCount += attrs.getLength();
59}
60
61void SAX2CountHandlers::characters(  const   XMLCh* const   /* chars */
62                                                                    , const XMLSize_t length)
63{
64    fCharacterCount += length;
65}
66
67void SAX2CountHandlers::ignorableWhitespace( const   XMLCh* const /* chars */
68                                                                                    , const XMLSize_t length)
69{
70    fSpaceCount += length;
71}
72
73void SAX2CountHandlers::startDocument()
74{
75    fAttrCount = 0;
76    fCharacterCount = 0;
77    fElementCount = 0;
78    fSpaceCount = 0;
79}
80
81
82// ---------------------------------------------------------------------------
83//  SAX2CountHandlers: Overrides of the SAX ErrorHandler interface
84// ---------------------------------------------------------------------------
85void SAX2CountHandlers::error(const SAXParseException& e)
86{
87    fSawErrors = true;
88    XERCES_STD_QUALIFIER cerr << "\nError at file " << StrX(e.getSystemId())
89                 << ", line " << e.getLineNumber()
90                 << ", char " << e.getColumnNumber()
91         << "\n  Message: " << StrX(e.getMessage()) << XERCES_STD_QUALIFIER endl;
92}
93
94void SAX2CountHandlers::fatalError(const SAXParseException& e)
95{
96    fSawErrors = true;
97    XERCES_STD_QUALIFIER cerr << "\nFatal Error at file " << StrX(e.getSystemId())
98                 << ", line " << e.getLineNumber()
99                 << ", char " << e.getColumnNumber()
100         << "\n  Message: " << StrX(e.getMessage()) << XERCES_STD_QUALIFIER endl;
101}
102
103void SAX2CountHandlers::warning(const SAXParseException& e)
104{
105    XERCES_STD_QUALIFIER cerr << "\nWarning at file " << StrX(e.getSystemId())
106                 << ", line " << e.getLineNumber()
107                 << ", char " << e.getColumnNumber()
108         << "\n  Message: " << StrX(e.getMessage()) << XERCES_STD_QUALIFIER endl;
109}
110
111void SAX2CountHandlers::resetErrors()
112{
113    fSawErrors = false;
114}
Note: See TracBrowser for help on using the repository browser.