~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to doc/html/qxmlsimplereader.html

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-08-24 04:09:09 UTC
  • Revision ID: james.westby@ubuntu.com-20050824040909-xmxe9jfr4a0w5671
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?xml version="1.0" encoding="iso-8859-1"?>
 
2
<!DOCTYPE html
 
3
    PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
 
4
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
 
5
<!-- /tmp/qt-4.0.0-espenr-1119621036935/qt-x11-opensource-desktop-4.0.0/src/xml/qxml.cpp -->
 
6
<head>
 
7
    <title>Qt 4.0: QXmlSimpleReader Class Reference</title>
 
8
    <style>h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm; }
 
9
a:link { color: #004faf; text-decoration: none }
 
10
a:visited { color: #672967; text-decoration: none }
 
11
td.postheader { font-family: sans-serif }
 
12
tr.address { font-family: sans-serif }
 
13
body { background: #ffffff; color: black; }</style>
 
14
</head>
 
15
<body>
 
16
<table border="0" cellpadding="0" cellspacing="0" width="100%">
 
17
<tr>
 
18
<td align="left" valign="top" width="32"><img src="images/qt-logo.png" align="left" width="32" height="32" border="0" /></td>
 
19
<td width="1">&nbsp;&nbsp;</td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a>&nbsp;&middot; <a href="classes.html"><font color="#004faf">All&nbsp;Classes</font></a>&nbsp;&middot; <a href="mainclasses.html"><font color="#004faf">Main&nbsp;Classes</font></a>&nbsp;&middot; <a href="annotated.html"><font color="#004faf">Annotated</font></a>&nbsp;&middot; <a href="groups.html"><font color="#004faf">Grouped&nbsp;Classes</font></a>&nbsp;&middot; <a href="functions.html"><font color="#004faf">Functions</font></a></td>
 
20
<td align="right" valign="top" width="230"><img src="images/trolltech-logo.png" align="right" width="203" height="32" border="0" /></td></tr></table><h1 align="center">QXmlSimpleReader Class Reference</h1>
 
21
<p>The QXmlSimpleReader class provides an implementation of a simple XML parser. <a href="#details">More...</a></p>
 
22
<pre>#include &lt;QXmlSimpleReader&gt;</pre><p>Part of the <a href="qtxml.html">QtXml</a> module.</p>
 
23
<p>Inherits <a href="qxmlreader.html">QXmlReader</a>.</p>
 
24
<p><b>Note:</b> All the functions in this class are <a href="threads.html#reentrant">reentrant</a>.</p>
 
25
<ul>
 
26
<li><a href="qxmlsimplereader-members.html">List of all members, including inherited members</a></li>
 
27
</ul>
 
28
<a name="public-functions"></a>
 
29
<h3>Public Functions</h3>
 
30
<ul>
 
31
<li><div class="fn"/><b><a href="qxmlsimplereader.html#QXmlSimpleReader">QXmlSimpleReader</a></b> ()</li>
 
32
<li><div class="fn"/>virtual <b><a href="qxmlsimplereader.html#dtor.QXmlSimpleReader">~QXmlSimpleReader</a></b> ()</li>
 
33
<li><div class="fn"/>virtual bool <b><a href="qxmlsimplereader.html#parse-3">parse</a></b> ( const QXmlInputSource * <i>input</i>, bool <i>incremental</i> )</li>
 
34
<li><div class="fn"/>virtual bool <b><a href="qxmlsimplereader.html#parseContinue">parseContinue</a></b> ()</li>
 
35
<li><div class="fn"/>virtual void <b><a href="qxmlsimplereader.html#setFeature">setFeature</a></b> ( const QString &amp; <i>name</i>, bool <i>enable</i> )</li>
 
36
</ul>
 
37
<ul>
 
38
<li><div class="fn"/>19 public functions inherited from <a href="qxmlreader.html#public-functions">QXmlReader</a></li>
 
39
</ul>
 
40
<a name="details"></a>
 
41
<hr />
 
42
<h2>Detailed Description</h2>
 
43
<p>The QXmlSimpleReader class provides an implementation of a simple XML parser.</p>
 
44
<p>This XML reader is suitable for a wide range of applications. It is able to parse well-formed XML and can report the namespaces of elements to a content handler; however, it does not parse any external entities.</p>
 
45
<p>The easiest pattern of use for this class is to create a reader instance, define an input source, specify the handlers to be used by the reader, and parse the data.</p>
 
46
<p>For example, we could use a <a href="qfile.html">QFile</a> to supply the input. Here, we create a reader, and define an input source to be used by the reader:</p>
 
47
<pre>&nbsp;       QXmlSimpleReader xmlReader;
 
48
        QXmlInputSource *source = new QXmlInputSource(file);</pre>
 
49
<p>A handler lets us perform actions when the reader encounters certain types of content, or if errors in the input are found. The reader must be told which handler to use for each type of event. For many common applications, we can create a custom handler by subclassing <a href="qxmldefaulthandler.html">QXmlDefaultHandler</a>, and use this to handle both error and content events:</p>
 
50
<pre>&nbsp;       Handler *handler = new Handler;
 
51
        xmlReader.setContentHandler(handler);
 
52
        xmlReader.setErrorHandler(handler);</pre>
 
53
<p>If you don't set at least the content and error handlers, the parser will fall back on its default behavior---and will do nothing.</p>
 
54
<p>The most convenient way to handle the input is to read it in a single pass using the <a href="qxmlsimplereader.html#parse">parse</a>() function with an argument that specifies the input source:</p>
 
55
<pre>&nbsp;       bool ok = xmlReader.parse(source);
 
56
 
 
57
        if (!ok)
 
58
            std::cout &lt;&lt; &quot;Parsing failed.&quot; &lt;&lt; std::endl;</pre>
 
59
<p>If you can't parse the entire input in one go (for example, it is huge, or is being delivered over a network connection), data can be fed to the parser in pieces. This is achieved by telling <a href="qxmlsimplereader.html#parse">parse</a>() to work incrementally, and making subsequent calls to the <a href="qxmlsimplereader.html#parseContinue">parseContinue</a>() function, until all the data has been processed.</p>
 
60
<p>A common way to perform incremental parsing is to connect the <tt>readyRead()</tt> signal of the input source to a slot, and handle the incoming data there. For example, the following code shows how a parser for <a href="http://web.resource.org/rss/1.0/">RSS feeds</a> can be used to incrementally parse data that it receives from a <a href="qhttp.html">QHttp</a> object:</p>
 
61
<pre>&nbsp;   void RSSListing::readData(const QHttpResponseHeader &amp;resp)
 
62
    {
 
63
        bool ok;
 
64
 
 
65
        if (resp.statusCode() != 200)
 
66
            http.abort();
 
67
        else {
 
68
            xmlInput.setData(http.readAll());
 
69
 
 
70
            if (newInformation) {
 
71
                ok = xmlReader.parse(&amp;xmlInput, true);
 
72
                newInformation = false;
 
73
            }
 
74
            else
 
75
                ok = xmlReader.parseContinue();
 
76
 
 
77
            if (!ok)
 
78
                http.abort();
 
79
        }
 
80
    }</pre>
 
81
<p>Aspects of the parsing behavior can be adapted using <a href="qxmlsimplereader.html#setFeature">setFeature</a>() and <a href="qxmlsimplereader.html#setProperty">setProperty</a>(). For example, the following code could be used to enable reporting of namespace prefixes to the content handler:</p>
 
82
<pre>&nbsp;   xmlReader.setFeature(&quot;http://xml.org/sax/features/namespace-prefixes&quot;, true);</pre>
 
83
<hr />
 
84
<h2>Member Function Documentation</h2>
 
85
<h3 class="fn"><a name="QXmlSimpleReader"></a>QXmlSimpleReader::QXmlSimpleReader ()</h3>
 
86
<p>Constructs a simple XML reader.</p>
 
87
<h3 class="fn"><a name="dtor.QXmlSimpleReader"></a>QXmlSimpleReader::~QXmlSimpleReader ()&nbsp;&nbsp;<tt> [virtual]</tt></h3>
 
88
<p>Destroys the simple XML reader.</p>
 
89
<h3 class="fn"><a name="parse-3"></a>bool QXmlSimpleReader::parse ( const <a href="qxmlinputsource.html">QXmlInputSource</a> * <i>input</i>, bool <i>incremental</i> )&nbsp;&nbsp;<tt> [virtual]</tt></h3>
 
90
<p>This is an overloaded member function, provided for convenience. It behaves essentially like the above function.</p>
 
91
<p>Reads an XML document from <i>input</i> and parses it. Returns true if the parsing is completed successfully; otherwise returns false, indicating that an error occurred.</p>
 
92
<p>If <i>incremental</i> is false, this function will return false if the XML file is not read completely. The parsing cannot be continued in this case.</p>
 
93
<p>If <i>incremental</i> is true, the parser does not return false if it reaches the end of the <i>input</i> before reaching the end of the XML file. Instead, it stores the state of the parser so that parsing can be continued later when more data is available. In such a case, you can use the function <a href="qxmlsimplereader.html#parseContinue">parseContinue</a>() to continue with parsing. This class stores a pointer to the input source <i>input</i> and the <a href="qxmlsimplereader.html#parseContinue">parseContinue</a>() function tries to read from that input source. Therefore, you should not delete the input source <i>input</i> until you no longer need to call <a href="qxmlsimplereader.html#parseContinue">parseContinue</a>().</p>
 
94
<p>If this function is called with <i>incremental</i> set to true while an incremental parse is in progress, a new parsing session will be started, and the previous session will be lost.</p>
 
95
<p>See also <a href="qxmlsimplereader.html#parseContinue">parseContinue</a>() and <a href="qtcpsocket.html">QTcpSocket</a>.</p>
 
96
<h3 class="fn"><a name="parseContinue"></a>bool QXmlSimpleReader::parseContinue ()&nbsp;&nbsp;<tt> [virtual]</tt></h3>
 
97
<p>Continues incremental parsing, taking input from the <a href="qxmlinputsource.html">QXmlInputSource</a> that was specified with the most recent call to <a href="qxmlsimplereader.html#parse">parse</a>(). To use this function, you <i>must</i> have called <a href="qxmlsimplereader.html#parse">parse</a>() with the incremental argument set to true.</p>
 
98
<p>Returns false if a parsing error occurs; otherwise returns true, even if the end of the XML file has not been reached. You can continue parsing at a later stage by calling this function again when there is more data available to parse.</p>
 
99
<p>Calling this function when there is no data available in the input source indicates to the reader that the end of the XML file has been reached. If the input supplied up to this point was not well-formed then a parsing error occurs, and false is returned. If the input supplied was well-formed, true is returned. It is important to end the input in this way because it allows you to reuse the reader to parse other XML files.</p>
 
100
<p>Calling this function after the end of file has been reached, but without available data will cause false to be returned whether the previous input was well-formed or not.</p>
 
101
<p>See also <a href="qxmlsimplereader.html#parse">parse</a>(), <a href="qxmlinputsource.html#data">QXmlInputSource::data</a>(), and <a href="qxmlinputsource.html#next">QXmlInputSource::next</a>().</p>
 
102
<h3 class="fn"><a name="setFeature"></a>void QXmlSimpleReader::setFeature ( const <a href="qstring.html">QString</a> &amp; <i>name</i>, bool <i>enable</i> )&nbsp;&nbsp;<tt> [virtual]</tt></h3>
 
103
<p>Turns on the feature <i>name</i> if <i>enable</i> is true; otherwise turns it off.</p>
 
104
<p>The <i>name</i> parameter must be one of the following strings:</p>
 
105
<table align="center" cellpadding="2" cellspacing="1" border="0">
 
106
<tr valign="top" bgcolor="#a2c511"><th>Feature</th><th>Default</th><th>Notes</th></tr>
 
107
<tr valign="top" bgcolor="#f0f0f0"><td><i>http://xml.org/sax/features/namespaces</i></td><td>true</td><td>If enabled, namespaces are reported to the content handler.</td></tr>
 
108
<tr valign="top" bgcolor="#e0e0e0"><td><i>http://xml.org/sax/features/namespace-prefixes</i></td><td>false</td><td>If enabled, the original prefixed names and attributes used for namespace declarations are reported.</td></tr>
 
109
<tr valign="top" bgcolor="#f0f0f0"><td><i>http://trolltech.com/xml/features/report-whitespace-only-CharData</i></td><td>true</td><td>If enabled, CharData that consist of only whitespace characters are reported using <a href="qxmlcontenthandler.html#characters">QXmlContentHandler::characters</a>().</td></tr>
 
110
<tr valign="top" bgcolor="#e0e0e0"><td><i>http://trolltech.com/xml/features/report-start-end-entity</i></td><td>false</td><td>If enabled, the parser reports QXmlContentHandler::startEntity() and QXmlContentHandler::endEntity() events, so character data might be reported in chunks. If disabled, the parser does not report these events, but silently substitutes the entities, and reports the character data in one chunk.</td></tr>
 
111
</table>
 
112
<p>More information about features can be found in the <a href="xml.html#sax2features">Qt SAX2 overview.</a></p>
 
113
<p>Reimplemented from <a href="qxmlreader.html#setFeature">QXmlReader</a>.</p>
 
114
<p>See also <a href="qxmlsimplereader.html#feature">feature</a>() and <a href="qxmlsimplereader.html#hasFeature">hasFeature</a>().</p>
 
115
<p /><address><hr /><div align="center">
 
116
<table width="100%" cellspacing="0" border="0"><tr class="address">
 
117
<td width="30%">Copyright &copy; 2005 <a href="trolltech.html">Trolltech</a></td>
 
118
<td width="40%" align="center"><a href="trademarks.html">Trademarks</a></td>
 
119
<td width="30%" align="right"><div align="right">Qt 4.0.0</div></td>
 
120
</tr></table></div></address></body>
 
121
</html>