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 | |
---|
14 | MySAXHandler::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 | |
---|
21 | MySAXHandler::~MySAXHandler() {} |
---|
22 | |
---|
23 | // Output FormatterTarget interface |
---|
24 | //-------------------------------------------------------------------------------- |
---|
25 | void MySAXHandler::writeChars(const XMLByte* const toWrite) {} |
---|
26 | |
---|
27 | void MySAXHandler::writeChars(const XMLByte* const toWrite, const unsigned int count, XMLFormatter* const formatter) { |
---|
28 | // writing to the destination file "out" |
---|
29 | out.write ((char *) toWrite, (int) count) ; |
---|
30 | } |
---|
31 | |
---|
32 | |
---|
33 | //DocumentHandler |
---|
34 | //-------------------------------------------------------------------------------- |
---|
35 | void MySAXHandler::startDocument() { |
---|
36 | // cout<<endl<<"startDocument \n"<<endl; |
---|
37 | } |
---|
38 | |
---|
39 | void MySAXHandler::endDocument() { |
---|
40 | // cout<<endl<<"\nendDocument "<<endl; |
---|
41 | } |
---|
42 | |
---|
43 | void MySAXHandler::startElement(const XMLCh* const uri, const XMLCh* const localname, |
---|
44 | const XMLCh* const qName, const Attributes& attributes) |
---|
45 | { |
---|
46 | // fFormatter << XMLFormatter::NoEscapes << chOpenAngle; // opens the tag "<" |
---|
47 | |
---|
48 | fFormatter << localname << chSpace << chColon << chLF ; |
---|
49 | |
---|
50 | unsigned int len = attributes.getLength(); |
---|
51 | for (unsigned int index = 0; index < len; index++) { |
---|
52 | fFormatter << XMLFormatter::NoEscapes << chSpace ; |
---|
53 | // fFormatter << attributes.getLocalName(index) ; |
---|
54 | |
---|
55 | fFormatter // << chEqual << chDoubleQuote |
---|
56 | << XMLFormatter::AttrEscapes |
---|
57 | << attributes.getValue(index) |
---|
58 | << XMLFormatter::NoEscapes << chSpace |
---|
59 | /* << chDoubleQuote*/; |
---|
60 | } |
---|
61 | // fFormatter << chCloseAngle; // closes the tag ">" |
---|
62 | } |
---|
63 | |
---|
64 | void MySAXHandler::endElement(const XMLCh* const uri, const XMLCh* const localname, |
---|
65 | const XMLCh* const qname) |
---|
66 | { |
---|
67 | // fFormatter << XMLFormatter::NoEscapes << chOpenAngle <<chForwardSlash; |
---|
68 | // fFormatter << localname ;//<< chCloseAngle; |
---|
69 | } |
---|
70 | |
---|
71 | void MySAXHandler::characters(const XMLCh* const chars, const unsigned int length) { |
---|
72 | // fFormatter.formatBuf(chars, length, XMLFormatter::CharEscapes); |
---|
73 | } |
---|
74 | |
---|
75 | void MySAXHandler::ignorableWhitespace(const XMLCh* const chars, const unsigned int length) { |
---|
76 | fFormatter.formatBuf(chars, length, XMLFormatter::NoEscapes); |
---|
77 | } |
---|
78 | |
---|
79 | |
---|
80 | void MySAXHandler::processingInstruction (const XMLCh* const target, const XMLCh* const data ) { |
---|
81 | // cout<<"Processing Instruction : "<<target<<" - "<<data; |
---|
82 | } |
---|
83 | |
---|
84 | // MySAXHandler: Overrides of the SAX ErrorHandler interface |
---|
85 | //-------------------------------------------------------------------------------- |
---|
86 | void MySAXHandler::error(const SAXParseException& e) { |
---|
87 | cerr << "\nError at file " << StrX(e.getSystemId()) |
---|
88 | << ", line " << e.getLineNumber() |
---|
89 | << ", char " << e.getColumnNumber() |
---|
90 | << "\n Message: " << StrX(e.getMessage()) << endl; |
---|
91 | } |
---|
92 | |
---|
93 | void MySAXHandler::fatalError(const SAXParseException& e) { |
---|
94 | cerr << "\nFatal Error at file " << StrX(e.getSystemId()) |
---|
95 | << ", line " << e.getLineNumber() |
---|
96 | << ", char " << e.getColumnNumber() |
---|
97 | << "\n Message: " << StrX(e.getMessage()) << endl; |
---|
98 | } |
---|
99 | |
---|
100 | void MySAXHandler::warning(const SAXParseException& e) { |
---|
101 | cerr << "\nWarning at file " << StrX(e.getSystemId()) |
---|
102 | << ", line " << e.getLineNumber() |
---|
103 | << ", char " << e.getColumnNumber() |
---|
104 | << "\n Message: " << StrX(e.getMessage()) << endl; |
---|
105 | } |
---|
106 | |
---|
107 | |
---|