00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 #include <cc++/common.h>
00043 #include <iostream>
00044 #include <cstdlib>
00045
00046 #ifdef CCXX_NAMESPACES
00047 using namespace std;
00048 using namespace ost;
00049 #endif
00050
00051 class myXMLParser : public URLStream, public XMLStream
00052 {
00053 private:
00054 void httpHeader(const char *header, const char *value) {
00055 cout << "HEADER " << header << "=" << value << endl;
00056 }
00057
00058 int read(unsigned char *buffer, size_t len) {
00059 URLStream::read((char *)buffer, len);
00060 len = gcount();
00061 return len;
00062 }
00063
00064 void startDocument(void) {
00065 cout << "START DOCUMENT" << endl;
00066 }
00067
00068 void endDocument(void) {
00069 cout << "END DOCUMENT" << endl;
00070 }
00071
00072 void characters(const unsigned char *text, size_t len) {
00073 cout << "CHARS=";
00074 while(len--)
00075 cout << *(text++);
00076 cout << endl;
00077 }
00078
00079 void comment(const char *text) {
00080 cout << "COMMENT=" << text << endl;
00081 }
00082
00083 void startElement(const unsigned char *name, const unsigned char **attr) {
00084 cout << "<" << name;
00085 if(attr) {
00086 while(*attr) {
00087 cout << " " << *(attr++);
00088 cout << "=" << *(attr++);
00089 }
00090 }
00091 cout << ">" << endl;
00092 }
00093
00094 void endElement(const unsigned char *name) {
00095 cout << "</" << name << ">" << endl;
00096 }
00097 public:
00098 void Close(void) {
00099 URLStream::close();
00100 }
00101 };
00102
00103 int main(int argc, char **argv)
00104 {
00105 myXMLParser xml;
00106 URLStream::Error status;
00107
00108
00109 #ifdef CCXX_EXCEPTIONS
00110 try {
00111 #endif
00112 while(--argc) {
00113 ++argv;
00114 cout << "fetching " << *argv << endl;
00115 status = xml.get(*argv);
00116 if(status) {
00117 cout << "failed; reason=" << status << endl;
00118 xml.Close();
00119 continue;
00120 }
00121 cout << "Parsing..." << endl;
00122 if(!xml.parse())
00123 cout << "not well formed..." << endl;
00124 xml.Close();
00125 cout << ends;
00126 }
00127 #ifdef CCXX_EXCEPTIONS
00128 }
00129 catch(...) {
00130 cerr << "url " << *argv << " failed" << endl;
00131 }
00132 #endif
00133 }
00134