source: branches/profile/XML_IMPORT/IMP_TREE/MySAXHandler.cxx

Last change on this file was 7811, checked in by westram, 14 years ago

merge from dev [7748] [7749] [7750]

  • comments (C→C++ style)
  • fixed umlauts in TREEGEN
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.0 KB
Line 
1#include <fstream.h>
2#include <stdio.h>
3#include <stdlib.h>
4#include <string.h>
5#include <iostream.h>
6#include <xercesc/util/XMLUniDefs.hpp>
7#include <xercesc/sax2/Attributes.hpp>
8#include <xercesc/sax/SAXParseException.hpp>
9#include <xercesc/sax/SAXException.hpp>
10#include "testParser.hxx"
11
12#include <strstream.h>
13
14MySAXHandler::MySAXHandler(const char* const encodingName, const XMLFormatter::UnRepFlags unRepFlags, ofstream &outFile) :
15    fFormatter(encodingName, this, XMLFormatter::NoEscapes, unRepFlags),
16    out(outFile)
17{
18    //    fFormatter << fFormatter.getEncodingName(); //getting the encoding name
19}
20
21MySAXHandler::~MySAXHandler()
22{
23}
24
25// Output FormatterTarget interface
26//--------------------------------------------------------------------------------
27void MySAXHandler::writeChars(const XMLByte* const toWrite)
28{
29}
30
31void MySAXHandler::writeChars(const XMLByte* const toWrite, const unsigned int count,
32                              XMLFormatter* const formatter)
33{
34    // writing to the destination file "out"
35    out.write ((char *) toWrite, (int) count) ;
36}
37
38
39//DocumentHandler
40//--------------------------------------------------------------------------------
41void MySAXHandler::startDocument()
42{
43    //    cout<<endl<<"startDocument \n"<<endl;
44}
45
46void MySAXHandler::endDocument()
47{
48    //    cout<<endl<<"\nendDocument "<<endl;
49}
50
51void MySAXHandler::startElement(const XMLCh* const uri,   const XMLCh* const localname,
52                                const XMLCh* const qName, const Attributes&  attributes)
53{
54    //    fFormatter << XMLFormatter::NoEscapes << chOpenAngle;  // opens the tag "<"
55
56    fFormatter << localname << chSpace << chColon << chLF ;
57
58    unsigned int len = attributes.getLength();
59    for (unsigned int index = 0; index < len; index++)
60    {
61        fFormatter  << XMLFormatter::NoEscapes << chSpace ;
62        //        fFormatter  << attributes.getLocalName(index) ;
63
64        fFormatter // << chEqual << chDoubleQuote
65                    << XMLFormatter::AttrEscapes
66                    << attributes.getValue(index)
67                    << XMLFormatter::NoEscapes << chSpace
68            /*                    << chDoubleQuote*/;
69    }
70    //    fFormatter << chCloseAngle;  // closes the tag ">"
71}
72
73void MySAXHandler::endElement(const XMLCh* const uri,    const XMLCh* const localname,
74                               const XMLCh* const qname)
75{
76    //   fFormatter << XMLFormatter::NoEscapes << chOpenAngle <<chForwardSlash;
77    //    fFormatter << localname ;//<< chCloseAngle;
78}
79
80void MySAXHandler::characters(const XMLCh* const chars, const unsigned int length)
81{
82    //   fFormatter.formatBuf(chars, length, XMLFormatter::CharEscapes);
83}
84
85void MySAXHandler::ignorableWhitespace(const XMLCh* const chars, const unsigned int length)
86{
87    fFormatter.formatBuf(chars, length, XMLFormatter::NoEscapes);
88}
89
90
91void MySAXHandler::processingInstruction (const XMLCh* const target, const XMLCh* const data ) 
92{
93    //   cout<<"Processing Instruction : "<<target<<" - "<<data;
94}
95
96//  MySAXHandler: Overrides of the SAX ErrorHandler interface
97//--------------------------------------------------------------------------------
98void MySAXHandler::error(const SAXParseException& e)
99{
100    cerr << "\nError at file " << StrX(e.getSystemId())
101         << ", line "          << e.getLineNumber()
102         << ", char "          << e.getColumnNumber()
103         << "\n  Message: "    << StrX(e.getMessage()) << endl;
104}
105
106void MySAXHandler::fatalError(const SAXParseException& e)
107{
108    cerr << "\nFatal Error at file " << StrX(e.getSystemId())
109         << ", line "                << e.getLineNumber()
110         << ", char "                << e.getColumnNumber()
111         << "\n  Message: "          << StrX(e.getMessage()) << endl;
112}
113
114void MySAXHandler::warning(const SAXParseException& e)
115{
116    cerr << "\nWarning at file " << StrX(e.getSystemId())
117         << ", line "            << e.getLineNumber()
118         << ", char "            << e.getColumnNumber()
119         << "\n  Message: "      << StrX(e.getMessage()) << endl;
120}
121
122
Note: See TracBrowser for help on using the repository browser.