| 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 | } |
|---|
| 24 | |
|---|
| 25 | // Output FormatterTarget interface |
|---|
| 26 | //-------------------------------------------------------------------------------- |
|---|
| 27 | void MySAXHandler::writeChars(const XMLByte* const toWrite) |
|---|
| 28 | { |
|---|
| 29 | } |
|---|
| 30 | |
|---|
| 31 | void 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 | //-------------------------------------------------------------------------------- |
|---|
| 41 | void MySAXHandler::startDocument() |
|---|
| 42 | { |
|---|
| 43 | // cout<<endl<<"startDocument \n"<<endl; |
|---|
| 44 | } |
|---|
| 45 | |
|---|
| 46 | void MySAXHandler::endDocument() |
|---|
| 47 | { |
|---|
| 48 | // cout<<endl<<"\nendDocument "<<endl; |
|---|
| 49 | } |
|---|
| 50 | |
|---|
| 51 | void 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 | |
|---|
| 73 | void 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 | |
|---|
| 80 | void MySAXHandler::characters(const XMLCh* const chars, const unsigned int length) |
|---|
| 81 | { |
|---|
| 82 | // fFormatter.formatBuf(chars, length, XMLFormatter::CharEscapes); |
|---|
| 83 | } |
|---|
| 84 | |
|---|
| 85 | void MySAXHandler::ignorableWhitespace(const XMLCh* const chars, const unsigned int length) |
|---|
| 86 | { |
|---|
| 87 | fFormatter.formatBuf(chars, length, XMLFormatter::NoEscapes); |
|---|
| 88 | } |
|---|
| 89 | |
|---|
| 90 | |
|---|
| 91 | void 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 | //-------------------------------------------------------------------------------- |
|---|
| 98 | void 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 | |
|---|
| 106 | void 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 | |
|---|
| 114 | void 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 | |
|---|