Sophie

Sophie

distrib > Mandriva > 2007.0 > i586 > by-pkgid > ad1ba1135a9c9eeffc2e538163e00373 > files > 894

libCommonC++2_1.4-devel-1.4.1-1mdv2007.0.i586.rpm

\section{xmlfetch.cpp}


\footnotesize\begin{verbatim}1 // Copyright (C) 2001 Open Source Telecom Corporation.
2 //
3 // This program is free software; you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation; either version 2 of the License, or
6 // (at your option) any later version.
7 //
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with this program; if not, write to the Free Software 
15 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16 // 
17 // As a special exception to the GNU General Public License, permission is 
18 // granted for additional uses of the text contained in its release 
19 // of Common C++.
20 // 
21 // The exception is that, if you link the Common C++ library with other
22 // files to produce an executable, this does not by itself cause the
23 // resulting executable to be covered by the GNU General Public License.
24 // Your use of that executable is in no way restricted on account of
25 // linking the Common C++ library code into it.
26 //
27 // This exception does not however invalidate any other reasons why
28 // the executable file might be covered by the GNU General Public License.
29 //
30 // This exception applies only to the code released under the 
31 // name Common C++.  If you copy code from other releases into a copy of
32 // Common C++, as the General Public License permits, the exception does
33 // not apply to the code that you add in this way.  To avoid misleading
34 // anyone as to the status of such modified files, you must delete
35 // this exception notice from them.
36 // 
37 // If you write modifications of your own for Common C++, it is your choice
38 // whether to permit this exception to apply to your modifications.
39 // If you do not wish that, delete this exception notice.
40 
41 #include <cc++/common.h>
42 #include <iostream>
43 #include <cstdlib>
44 
45 #ifdef  CCXX_NAMESPACES
46 using namespace std;
47 using namespace ost;
48 #endif
49 
50 class myXMLParser : public URLStream, public XMLStream
51 {
52 private:
53         void httpHeader(const char *header, const char *value)
54         {
55                 cout << "HEADER " << header << "=" << value << endl;
56         }       
57 
58         int read(unsigned char *buffer, size_t len)
59         {
60                 URLStream::read((char *)buffer, len);
61                 len = gcount();
62                 return len;
63         }
64 
65         void startDocument(void)
66         {
67                 cout << "START DOCUMENT" << endl;
68         }
69 
70         void endDocument(void)
71         {
72                 cout << "END DOCUMENT" << endl;
73         }
74 
75         void characters(const unsigned char *text, size_t len)
76         {
77                 cout << "CHARS=";
78                 while(len--)
79                         cout << *(text++);
80                 cout << endl;
81         }
82 
83         void comment(const char *text)
84         {
85                 cout << "COMMENT=" << text << endl;
86         }
87 
88         void startElement(const unsigned char *name, const unsigned char **attr)
89         {
90                 cout << "<" << name;
91                 if(attr)
92                 {
93                         while(*attr)
94                         {
95                                 cout << " " << *(attr++);
96                                 cout << "=" << *(attr++);
97                         }
98                 }
99                 cout << ">" << endl;
100         }
101 
102         void endElement(const unsigned char *name)
103         {
104                 cout << "</" << name << ">" << endl;
105         }
106 public:
107         void Close(void)
108         {
109                 URLStream::close();
110         }
111 };
112 
113 int main(int argc, char **argv)
114 {
115         myXMLParser xml;
116         URLStream::Error status;
117 
118 //      url.setProxy("home.sys", 8000);
119 #ifdef  CCXX_EXCEPTIONS
120         try
121         {
122 #endif
123                 while(--argc)
124                 {
125                         ++argv;
126                         cout << "fetching " << *argv << endl;
127                         status = xml.get(*argv);
128                         if(status)
129                         {
130                                 cout << "failed; reason=" << status << endl;
131                                 xml.Close();
132                                 continue;
133                         }
134                         cout << "Parsing..." << endl;
135                         if(!xml.parse())
136                                 cout << "not well formed..." << endl;
137                         xml.Close();
138                         cout << ends;
139                 }
140 #ifdef  CCXX_EXCEPTIONS
141         }
142         catch(...)
143         {
144                 cerr << "url " << *argv << " failed" << endl;
145         }
146 #endif
147 }
148 
\end{verbatim}
\normalsize