source: icXML/icXML-devel/samples/src/SAXCount/SAXCountHandlers.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.6 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: SAXCountHandlers.cpp 557282 2007-07-18 14:54:15Z amassari $
20 */
21
22// ---------------------------------------------------------------------------
23//  Includes
24// ---------------------------------------------------------------------------
25#include "SAXCount.hpp"
26#include <xercesc/sax/AttributeList.hpp>
27#include <xercesc/sax/SAXParseException.hpp>
28#include <xercesc/sax/SAXException.hpp>
29
30
31
32// ---------------------------------------------------------------------------
33//  SAXCountHandlers: Constructors and Destructor
34// ---------------------------------------------------------------------------
35SAXCountHandlers::SAXCountHandlers() :
36
37    fAttrCount(0)
38    , fCharacterCount(0)
39    , fElementCount(0)
40    , fSpaceCount(0)
41    , fSawErrors(false)
42{
43}
44
45SAXCountHandlers::~SAXCountHandlers()
46{
47}
48
49
50// ---------------------------------------------------------------------------
51//  SAXCountHandlers: Implementation of the SAX DocumentHandler interface
52// ---------------------------------------------------------------------------
53void SAXCountHandlers::startElement(const   XMLCh* const    /* name */
54                                    ,       AttributeList&  attributes)
55{
56    fElementCount++;
57    fAttrCount += attributes.getLength();
58}
59
60void SAXCountHandlers::characters(  const   XMLCh* const    /* chars */
61                                                                    , const XMLSize_t       length)
62{
63    fCharacterCount += length;
64}
65
66void SAXCountHandlers::ignorableWhitespace( const   XMLCh* const /* chars */
67                                                                                    , const XMLSize_t    length)
68{
69    fSpaceCount += length;
70}
71
72void SAXCountHandlers::resetDocument()
73{
74    fAttrCount = 0;
75    fCharacterCount = 0;
76    fElementCount = 0;
77    fSpaceCount = 0;
78}
79
80
81// ---------------------------------------------------------------------------
82//  SAXCountHandlers: Overrides of the SAX ErrorHandler interface
83// ---------------------------------------------------------------------------
84void SAXCountHandlers::error(const SAXParseException& e)
85{
86    fSawErrors = true;
87    XERCES_STD_QUALIFIER cerr << "\nError at file " << StrX(e.getSystemId())
88                 << ", line " << e.getLineNumber()
89                 << ", char " << e.getColumnNumber()
90         << "\n  Message: " << StrX(e.getMessage()) << XERCES_STD_QUALIFIER endl;
91}
92
93void SAXCountHandlers::fatalError(const SAXParseException& e)
94{
95    fSawErrors = true;
96    XERCES_STD_QUALIFIER cerr << "\nFatal Error at file " << StrX(e.getSystemId())
97                 << ", line " << e.getLineNumber()
98                 << ", char " << e.getColumnNumber()
99         << "\n  Message: " << StrX(e.getMessage()) << XERCES_STD_QUALIFIER endl;
100}
101
102void SAXCountHandlers::warning(const SAXParseException& e)
103{
104    XERCES_STD_QUALIFIER cerr << "\nWarning at file " << StrX(e.getSystemId())
105                 << ", line " << e.getLineNumber()
106                 << ", char " << e.getColumnNumber()
107         << "\n  Message: " << StrX(e.getMessage()) << XERCES_STD_QUALIFIER endl;
108}
109
110void SAXCountHandlers::resetErrors()
111{
112    fSawErrors = false;
113}
Note: See TracBrowser for help on using the repository browser.