Sophie

Sophie

distrib > Mandriva > current > i586 > media > main-updates > by-pkgid > ed376d6842ea322c25405e7c23b3bc12 > files > 676

libcommoncpp-devel-1.8.0-5.1mdv2010.1.i586.rpm

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>GNU CommonC++: xmlfetch.cpp</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<!-- Generated by Doxygen 1.6.3 -->
<div class="navigation" id="top">
  <div class="tabs">
    <ul>
      <li><a href="index.html"><span>Main&nbsp;Page</span></a></li>
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
      <li><a href="examples.html"><span>Examples</span></a></li>
    </ul>
  </div>
</div>
<div class="contents">
<h1>xmlfetch.cpp</h1><div class="fragment"><pre class="fragment"><span class="comment">// Copyright (C) 2001-2005 Open Source Telecom Corporation.</span>
<span class="comment">// Copyright (C) 2006-2008 David Sugar, Tycho Softworks.</span>
<span class="comment">//</span>
<span class="comment">// This program is free software; you can redistribute it and/or modify</span>
<span class="comment">// it under the terms of the GNU General Public License as published by</span>
<span class="comment">// the Free Software Foundation; either version 2 of the License, or</span>
<span class="comment">// (at your option) any later version.</span>
<span class="comment">//</span>
<span class="comment">// This program is distributed in the hope that it will be useful,</span>
<span class="comment">// but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<span class="comment">// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
<span class="comment">// GNU General Public License for more details.</span>
<span class="comment">//</span>
<span class="comment">// You should have received a copy of the GNU General Public License</span>
<span class="comment">// along with this program; if not, write to the Free Software</span>
<span class="comment">// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.</span>
<span class="comment">//</span>
<span class="comment">// As a special exception to the GNU General Public License, permission is</span>
<span class="comment">// granted for additional uses of the text contained in its release</span>
<span class="comment">// of Common C++.</span>
<span class="comment">//</span>
<span class="comment">// The exception is that, if you link the Common C++ library with other</span>
<span class="comment">// files to produce an executable, this does not by itself cause the</span>
<span class="comment">// resulting executable to be covered by the GNU General Public License.</span>
<span class="comment">// Your use of that executable is in no way restricted on account of</span>
<span class="comment">// linking the Common C++ library code into it.</span>
<span class="comment">//</span>
<span class="comment">// This exception does not however invalidate any other reasons why</span>
<span class="comment">// the executable file might be covered by the GNU General Public License.</span>
<span class="comment">//</span>
<span class="comment">// This exception applies only to the code released under the</span>
<span class="comment">// name Common C++.  If you copy code from other releases into a copy of</span>
<span class="comment">// Common C++, as the General Public License permits, the exception does</span>
<span class="comment">// not apply to the code that you add in this way.  To avoid misleading</span>
<span class="comment">// anyone as to the status of such modified files, you must delete</span>
<span class="comment">// this exception notice from them.</span>
<span class="comment">//</span>
<span class="comment">// If you write modifications of your own for Common C++, it is your choice</span>
<span class="comment">// whether to permit this exception to apply to your modifications.</span>
<span class="comment">// If you do not wish that, delete this exception notice.</span>

<span class="preprocessor">#include &lt;<a class="code" href="common_8h.html" title="GNU Common C++ global header.">cc++/common.h</a>&gt;</span>
<span class="preprocessor">#include &lt;iostream&gt;</span>
<span class="preprocessor">#include &lt;cstdlib&gt;</span>

<span class="preprocessor">#ifdef  CCXX_NAMESPACES</span>
<span class="preprocessor"></span><span class="keyword">using namespace </span>std;
<span class="keyword">using namespace </span>ost;
<span class="preprocessor">#endif</span>
<span class="preprocessor"></span>
<span class="keyword">class </span>myXMLParser : <span class="keyword">public</span> <a name="_a0"></a><a class="code" href="classost_1_1_u_r_l_stream.html" title="A URL processing version of TCPStream.">URLStream</a>, <span class="keyword">public</span> <a name="_a1"></a><a class="code" href="classost_1_1_x_m_l_stream.html" title="This class impliments a basic XML stream parser that can be used to examine an XML...">XMLStream</a>
{
<span class="keyword">private</span>:
        <span class="keywordtype">void</span> <a name="a2"></a><a class="code" href="classost_1_1_u_r_l_stream.html#a353ff6fd2ffb296082e357e45b53632e" title="Derived method to receive and parse http &amp;quot;headers&amp;quot;.">httpHeader</a>(<span class="keyword">const</span> <span class="keywordtype">char</span> *header, <span class="keyword">const</span> <span class="keywordtype">char</span> *value) {
                cout &lt;&lt; <span class="stringliteral">&quot;HEADER &quot;</span> &lt;&lt; header &lt;&lt; <span class="stringliteral">&quot;=&quot;</span> &lt;&lt; value &lt;&lt; endl;
        }

        <span class="keywordtype">int</span> <a name="a3"></a><a class="code" href="classost_1_1_x_m_l_stream.html#a64e401b6b98c28523719d021f11acd52" title="Read method to aquire data for the parser.">read</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> *buffer, <span class="keywordtype">size_t</span> len) {
                URLStream::read((<span class="keywordtype">char</span> *)buffer, len);
                len = gcount();
                <span class="keywordflow">return</span> len;
        }

        <span class="keywordtype">void</span> <a name="a4"></a><a class="code" href="classost_1_1_x_m_l_stream.html#a4a4305dffd6b1eb7cdb6afd373fec8ef" title="Identify start of document event.">startDocument</a>(<span class="keywordtype">void</span>) {
                cout &lt;&lt; <span class="stringliteral">&quot;START DOCUMENT&quot;</span> &lt;&lt; endl;
        }

        <span class="keywordtype">void</span> <a name="a5"></a><a class="code" href="classost_1_1_x_m_l_stream.html#abc1e0f16c8100aadfde6acec56c2029e" title="Identify end of document event.">endDocument</a>(<span class="keywordtype">void</span>) {
                cout &lt;&lt; <span class="stringliteral">&quot;END DOCUMENT&quot;</span> &lt;&lt; endl;
        }

        <span class="keywordtype">void</span> <a name="a6"></a><a class="code" href="classost_1_1_x_m_l_stream.html#af0962a8d37d7a17d8aff75c9409bf72f" title="Virtual to receive character text extracted from the document in the current element...">characters</a>(<span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> *text, <span class="keywordtype">size_t</span> len) {
                cout &lt;&lt; <span class="stringliteral">&quot;CHARS=&quot;</span>;
                <span class="keywordflow">while</span>(len--)
                        cout &lt;&lt; *(text++);
                cout &lt;&lt; endl;
        }

        <span class="keywordtype">void</span> <a name="a7"></a><a class="code" href="classost_1_1_x_m_l_stream.html#ad0dce01d08f35d642960867c0f5ccfbd" title="Virtual to receive embedded comments in an XML document being parsed.">comment</a>(<span class="keyword">const</span> <span class="keywordtype">char</span> *text) {
                cout &lt;&lt; <span class="stringliteral">&quot;COMMENT=&quot;</span> &lt;&lt; text &lt;&lt; endl;
        }

        <span class="keywordtype">void</span> <a name="a8"></a><a class="code" href="classost_1_1_x_m_l_stream.html#aa2ccb9652149b6e461902c102b8ccde6" title="Identify start of an element in the document.">startElement</a>(<span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> *name, <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> **attr) {
                cout &lt;&lt; <span class="stringliteral">&quot;&lt;&quot;</span> &lt;&lt; name;
                <span class="keywordflow">if</span>(attr) {
                        <span class="keywordflow">while</span>(*attr) {
                                cout &lt;&lt; <span class="stringliteral">&quot; &quot;</span> &lt;&lt; *(attr++);
                                cout &lt;&lt; <span class="stringliteral">&quot;=&quot;</span> &lt;&lt; *(attr++);
                        }
                }
                cout &lt;&lt; <span class="stringliteral">&quot;&gt;&quot;</span> &lt;&lt; endl;
        }

        <span class="keywordtype">void</span> <a name="a9"></a><a class="code" href="classost_1_1_x_m_l_stream.html#a74d63a5adf80d81d61888aad632f2b7d" title="Identify end of an element in the document.">endElement</a>(<span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> *name) {
                cout &lt;&lt; <span class="stringliteral">&quot;&lt;/&quot;</span> &lt;&lt; name &lt;&lt; <span class="stringliteral">&quot;&gt;&quot;</span> &lt;&lt; endl;
        }
<span class="keyword">public</span>:
        <span class="keywordtype">void</span> Close(<span class="keywordtype">void</span>) {
                URLStream::close();
        }
};

<span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> **argv)
{
        myXMLParser xml;
        <a class="code" href="classost_1_1_u_r_l_stream.html#a3cbe53f1c34d7fdbd73efa61edbf463d" title="Return error for url fetch.">URLStream::Error</a> status;

<span class="comment">//      url.setProxy(&quot;home.sys&quot;, 8000);</span>
<span class="preprocessor">#ifdef  CCXX_EXCEPTIONS</span>
<span class="preprocessor"></span>        <span class="keywordflow">try</span> {
<span class="preprocessor">#endif</span>
<span class="preprocessor"></span>                <span class="keywordflow">while</span>(--argc) {
                        ++argv;
                        cout &lt;&lt; <span class="stringliteral">&quot;fetching &quot;</span> &lt;&lt; *argv &lt;&lt; endl;
                        status = xml.get(*argv);
                        <span class="keywordflow">if</span>(status) {
                                cout &lt;&lt; <span class="stringliteral">&quot;failed; reason=&quot;</span> &lt;&lt; status &lt;&lt; endl;
                                xml.Close();
                                <span class="keywordflow">continue</span>;
                        }
                        cout &lt;&lt; <span class="stringliteral">&quot;Parsing...&quot;</span> &lt;&lt; endl;
                        <span class="keywordflow">if</span>(!xml.parse())
                                cout &lt;&lt; <span class="stringliteral">&quot;not well formed...&quot;</span> &lt;&lt; endl;
                        xml.Close();
                        cout &lt;&lt; ends;
                }
<span class="preprocessor">#ifdef  CCXX_EXCEPTIONS</span>
<span class="preprocessor"></span>        }
        <span class="keywordflow">catch</span>(...) {
                cerr &lt;&lt; <span class="stringliteral">&quot;url &quot;</span> &lt;&lt; *argv &lt;&lt; <span class="stringliteral">&quot; failed&quot;</span> &lt;&lt; endl;
        }
<span class="preprocessor">#endif</span>
<span class="preprocessor"></span>}

</pre></div> </div>
<hr class="footer"/><address style="text-align: right;"><small>Generated on Fri Nov 12 09:55:46 2010 for GNU CommonC++ by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.3 </small></address>
</body>
</html>