Sophie

Sophie

distrib > Mageia > 4 > i586 > by-pkgid > 28b9e36e96ce34b2567ae5b47a27b2c5 > files > 1233

python-qt4-doc-4.10.3-3.mga4.noarch.rpm

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
<html><head><title>QtXml Module</title><style>h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm }
a:link { color: #004faf; text-decoration: none }
a:visited { color: #672967; text-decoration: none }
td.postheader { font-family: sans-serif }
tr.address { font-family: sans-serif }
body { background: #ffffff; color: black; }
</style></head><body><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr /><td align="left" valign="top" width="32"><img align="left" border="0" height="32" src="images/rb-logo.png" width="32" /></td><td width="1">&#160;&#160;</td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a>&#160;&#183; <a href="classes.html"><font color="#004faf">All Classes</font></a>&#160;&#183; <a href="modules.html"><font color="#004faf">Modules</font></a></td></table><h1 align="center">QtXml Module<br /></h1><p>The QtXml module provides implementations of SAX and DOM. <a href="#details">More...</a></p><h3>Types</h3><ul><li><div class="fn" />class <b><a href="qdomattr.html">QDomAttr</a></b></li><li><div class="fn" />class <b><a href="qdomcdatasection.html">QDomCDATASection</a></b></li><li><div class="fn" />class <b><a href="qdomcharacterdata.html">QDomCharacterData</a></b></li><li><div class="fn" />class <b><a href="qdomcomment.html">QDomComment</a></b></li><li><div class="fn" />class <b><a href="qdomdocument.html">QDomDocument</a></b></li><li><div class="fn" />class <b><a href="qdomdocumentfragment.html">QDomDocumentFragment</a></b></li><li><div class="fn" />class <b><a href="qdomdocumenttype.html">QDomDocumentType</a></b></li><li><div class="fn" />class <b><a href="qdomelement.html">QDomElement</a></b></li><li><div class="fn" />class <b><a href="qdomentity.html">QDomEntity</a></b></li><li><div class="fn" />class <b><a href="qdomentityreference.html">QDomEntityReference</a></b></li><li><div class="fn" />class <b><a href="qdomimplementation.html">QDomImplementation</a></b></li><li><div class="fn" />class <b><a href="qdomnamednodemap.html">QDomNamedNodeMap</a></b></li><li><div class="fn" />class <b><a href="qdomnode.html">QDomNode</a></b></li><li><div class="fn" />class <b><a href="qdomnodelist.html">QDomNodeList</a></b></li><li><div class="fn" />class <b><a href="qdomnotation.html">QDomNotation</a></b></li><li><div class="fn" />class <b><a href="qdomprocessinginstruction.html">QDomProcessingInstruction</a></b></li><li><div class="fn" />class <b><a href="qdomtext.html">QDomText</a></b></li><li><div class="fn" />class <b><a href="qxmlattributes.html">QXmlAttributes</a></b></li><li><div class="fn" />class <b><a href="qxmlcontenthandler.html">QXmlContentHandler</a></b></li><li><div class="fn" />class <b><a href="qxmldeclhandler.html">QXmlDeclHandler</a></b></li><li><div class="fn" />class <b><a href="qxmldefaulthandler.html">QXmlDefaultHandler</a></b></li><li><div class="fn" />class <b><a href="qxmldtdhandler.html">QXmlDTDHandler</a></b></li><li><div class="fn" />class <b><a href="qxmlentityresolver.html">QXmlEntityResolver</a></b></li><li><div class="fn" />class <b><a href="qxmlerrorhandler.html">QXmlErrorHandler</a></b></li><li><div class="fn" />class <b><a href="qxmlinputsource.html">QXmlInputSource</a></b></li><li><div class="fn" />class <b><a href="qxmllexicalhandler.html">QXmlLexicalHandler</a></b></li><li><div class="fn" />class <b><a href="qxmllocator.html">QXmlLocator</a></b></li><li><div class="fn" />class <b><a href="qxmlnamespacesupport.html">QXmlNamespaceSupport</a></b></li><li><div class="fn" />class <b><a href="qxmlparseexception.html">QXmlParseException</a></b></li><li><div class="fn" />class <b><a href="qxmlreader.html">QXmlReader</a></b></li><li><div class="fn" />class <b><a href="qxmlsimplereader.html">QXmlSimpleReader</a></b></li></ul><a name="details" /><hr /><h2>Detailed Description</h2><p>The QtXml module provides implementations of SAX and DOM.</p>

<p>To import the module use, for example, the following statement:</p>

<pre>from PyQt4 import QtXml</pre>

<p>SAX is an event-based standard interface for XML parsers. The Qt interface follows the design of the SAX2 Java implementation. Its naming scheme was adapted to fit the Qt naming conventions. Details on SAX2 can be found at <a href="http://www.saxproject.org">http://www.saxproject.org</a>.</p>
<p>Support for SAX2 filters and the reader factory are under development. The Qt implementation does not include the SAX1 compatibility classes present in the Java interface. For an introduction to Qt's SAX2 classes see <a href="#the-qt-sax2-classes">The Qt SAX2 classes</a>.</p>
<p>DOM Level 2 is a W3C Recommendation for XML interfaces that maps the constituents of an XML document to a tree structure. The specification of DOM Level 2 can be found at <a href="http://www.w3.org/DOM/">http://www.w3.org/DOM/</a>. More information about the DOM classes in Qt is provided in the <a href="#dom">Qt DOM classes</a>.</p>
<p>In addition to SAX and DOM support, Qt's <a href="q3picture.html">Q3Picture</a> class can read and write SVG. Additional XML support is provided by the <a href="http://www.trolltech.com/products/solutions/index.html">Qt Solutions</a> group who provide, for example, classes that support SOAP and MML with the Qt XML classes.</p>

<p>Topics:</p>
<ul>
<li><a href="#the-qt-sax2-classes">The Qt SAX2 Classes</a></li>
<ul><li><a href="#introduction-to-sax2">Introduction to SAX2</a></li>
<li><a href="#sax2-features">SAX2 Features</a></li>
<li><a href="#namespace-support-via-features">Namespace Support via Features</a></li>
<ul><li><a href="#summary">Summary</a></li>
</ul>
<li><a href="#properties">Properties</a></li>
</ul>
<li><a href="#the-qt-dom-classes">The Qt DOM Classes</a></li>
<ul><li><a href="#introduction-to-dom">Introduction to DOM</a></li>
</ul>
<li><a href="#an-introduction-to-namespaces">An Introduction to Namespaces</a></li>
<ul><li><a href="#conventions-used-in-the-qt-xml-documentation">Conventions Used in the Qt XML Documentation</a></li>
</ul>
</ul>
<a name="the-qt-sax2-classes" />
<h3>The Qt SAX2 Classes</h3>
<a name="introduction-to-sax2" />
<h4>Introduction to SAX2</h4>
<p>The SAX2 interface is an event-driven mechanism to provide the user with document information. An "event" in this context means something reported by the parser, for example, it has encountered a start tag, or an end tag, etc.</p>
<p>To make it less abstract consider the following example:</p>
<pre>&#160;   &lt;quote&gt;A quotation.&lt;/quote&gt;</pre>
<p>Whilst reading (a SAX2 parser is usually referred to as "reader") the above document three events would be triggered:</p>
<ol type="1">
<li>A start tag occurs (<tt>&lt;quote&gt;</tt>).</li>
<li>Character data (i.e. text) is found, "A quotation.".</li>
<li>An end tag is parsed (<tt>&lt;/quote&gt;</tt>).</li>
</ol>
<p>Each time such an event occurs the parser reports it; you can set up event handlers to respond to these events.</p>
<p>Whilst this is a fast and simple approach to read XML documents, manipulation is difficult because data is not stored, simply handled and discarded serially. The <a href="#dom">DOM interface</a> reads in and stores the whole document in a tree structure; this takes more memory, but makes it easier to manipulate the document's structure..</p>
<p>The Qt XML module provides an abstract class, <a href="qxmlreader.html">QXmlReader</a>, that defines the interface for potential SAX2 readers. Qt includes a reader implementation, <a href="qxmlsimplereader.html">QXmlSimpleReader</a>, that is easy to adapt through subclassing.</p>
<p>The reader reports parsing events through special handler classes:</p>
<p><table align="center" border="0" cellpadding="2" cellspacing="1">
<tr bgcolor="#a2c511" valign="top"><th>Handler class</th><th>Description</th></tr>
<tr bgcolor="#f0f0f0" valign="top"><td><a href="qxmlcontenthandler.html">QXmlContentHandler</a></td><td>Reports events related to the content of a document (e.g. the start tag or characters).</td></tr>
<tr bgcolor="#e0e0e0" valign="top"><td><a href="qxmldtdhandler.html">QXmlDTDHandler</a></td><td>Reports events related to the DTD (e.g. notation declarations).</td></tr>
<tr bgcolor="#f0f0f0" valign="top"><td><a href="qxmlerrorhandler.html">QXmlErrorHandler</a></td><td>Reports errors or warnings that occurred during parsing.</td></tr>
<tr bgcolor="#e0e0e0" valign="top"><td><a href="qxmlentityresolver.html">QXmlEntityResolver</a></td><td>Reports external entities during parsing and allows users to resolve external entities themselves instead of leaving it to the reader.</td></tr>
<tr bgcolor="#f0f0f0" valign="top"><td><a href="qxmldeclhandler.html">QXmlDeclHandler</a></td><td>Reports further DTD related events (e.g. attribute declarations).</td></tr>
<tr bgcolor="#e0e0e0" valign="top"><td><a href="qxmllexicalhandler.html">QXmlLexicalHandler</a></td><td>Reports events related to the lexical structure of the document (the beginning of the DTD, comments etc.).</td></tr>
</table></p>
<p>These classes are abstract classes describing the interface. The <a href="qxmldefaulthandler.html">QXmlDefaultHandler</a> class provides a "do nothing" default implementation for all of them. Therefore users only need to overload the <a href="qxmldefaulthandler.html">QXmlDefaultHandler</a> functions they are interested in.</p>
<p>To read input XML data a special class <a href="qxmlinputsource.html">QXmlInputSource</a> is used.</p>
<p>Apart from those already mentioned, the following SAX2 support classes provide additional useful functionality:</p>
<p><table align="center" border="0" cellpadding="2" cellspacing="1">
<tr bgcolor="#a2c511" valign="top"><th>Class</th><th>Description</th></tr>
<tr bgcolor="#f0f0f0" valign="top"><td><a href="qxmlattributes.html">QXmlAttributes</a></td><td>Used to pass attributes in a start element event.</td></tr>
<tr bgcolor="#e0e0e0" valign="top"><td><a href="qxmllocator.html">QXmlLocator</a></td><td>Used to obtain the actual parsing position of an event.</td></tr>
<tr bgcolor="#f0f0f0" valign="top"><td><a href="qxmlnamespacesupport.html">QXmlNamespaceSupport</a></td><td>Used to implement namespace support for a reader. Note that namespaces do not change the parsing behavior. They are only reported through the handler.</td></tr>
</table></p>
<a name="sax2-features" />
<h4>SAX2 Features</h4>
<p>The behavior of an XML reader depends on its support for certain optional features. For example, a reader may have the feature "report attributes used for namespace declarations and prefixes along with the local name of a tag". Like every other feature this has a unique name represented by a URI: it is called <i>http://xml.org/sax/features/namespace-prefixes</i>.</p>
<p>The Qt SAX2 implementation can report whether the reader has particular functionality using the <a href="qxmlreader.html#hasFeature">QXmlReader.hasFeature</a>() function. Available features can be tested with <a href="qxmlreader.html#feature">QXmlReader.feature</a>(), and switched on or off using <a href="qxmlreader.html#setFeature">QXmlReader.setFeature</a>().</p>
<p>Consider the example</p>
<pre>&#160;   &lt;document xmlns:book = 'http://trolltech.com/fnord/book/'
              xmlns      = 'http://trolltech.com/fnord/' &gt;</pre>
<p>A reader that does not support the <i>http://xml.org/sax/features/namespace-prefixes</i> feature would report the element name <i>document</i> but not its attributes <i>xmlns:book</i> and <i>xmlns</i> with their values. A reader with the feature <i>http://xml.org/sax/features/namespace-prefixes</i> reports the namespace attributes if the <a href="qxmlreader.html#feature">feature</a> is switched on.</p>
<p>Other features include <i>http://xml.org/sax/features/namespace</i> (namespace processing, implies <i>http://xml.org/sax/features/namespace-prefixes</i>) and <i>http://xml.org/sax/features/validation</i> (the ability to report validation errors).</p>
<p>Whilst SAX2 leaves it to the user to define and implement whatever features are required, support for <i>http://xml.org/sax/features/namespace</i> (and thus <i>http://xml.org/sax/features/namespace-prefixes</i>) is mandantory. The <a href="qxmlsimplereader.html">QXmlSimpleReader</a> implementation of <a href="qxmlreader.html">QXmlReader</a>, supports them, and can do namespace processing.</p>
<p><a href="qxmlsimplereader.html">QXmlSimpleReader</a> is not validating, so it does not support <i>http://xml.org/sax/features/validation</i>.</p>
<a name="namespace-support-via-features" />
<h4>Namespace Support via Features</h4>
<p>As we have seen in the previous section, we can configure the behavior of the reader when it comes to namespace processing. This is done by setting and unsetting the <i>http://xml.org/sax/features/namespaces</i> and <i>http://xml.org/sax/features/namespace-prefixes</i> features.</p>
<p>They influence the reporting behavior in the following way:</p>
<ol type="1">
<li>Namespace prefixes and local parts of elements and attributes can be reported.</li>
<li>The qualified names of elements and attributes are reported.</li>
<li><a href="qxmlcontenthandler.html#startPrefixMapping">QXmlContentHandler.startPrefixMapping</a>() and <a href="qxmlcontenthandler.html#endPrefixMapping">QXmlContentHandler.endPrefixMapping</a>() are called by the reader.</li>
<li>Attributes that declare namespaces (i.e. the attribute <i>xmlns</i> and attributes starting with <i>xmlns:</i>) are reported.</li>
</ol>
<p>Consider the following element:</p>
<pre>&#160;   &lt;author xmlns:fnord = 'http://trolltech.com/fnord/'
                 title="Ms"
                 fnord:title="Goddess"
                 name="Eris Kallisti"/&gt;</pre>
<p>With <i>http://xml.org/sax/features/namespace-prefixes</i> set to true the reader will report four attributes; but with the <i>namespace-prefixes</i> feature set to false only three, with the <i>xmlns:fnord</i> attribute defining a namespace being "invisible" to the reader.</p>
<p>The <i>http://xml.org/sax/features/namespaces</i> feature is responsible for reporting local names, namespace prefixes and URIs. With <i>http://xml.org/sax/features/namespaces</i> set to true the parser will report <i>title</i> as the local name of the <i>fnord:title</i> attribute, <i>fnord</i> being the namespace prefix and <i>http://trolltech.com/fnord/</i> as the namespace URI. When <i>http://xml.org/sax/features/namespaces</i> is false none of them are reported.</p>
<p>In the current implementation the Qt XML classes follow the definition that the prefix <i>xmlns</i> itself isn't associated with any namespace at all (see <a href="http://www.w3.org/TR/1999/REC-xml-names-19990114/#ns-using">http://www.w3.org/TR/1999/REC-xml-names-19990114/#ns-using</a>). Therefore even with <i>http://xml.org/sax/features/namespaces</i> and <i>http://xml.org/sax/features/namespace-prefixes</i> both set to true the reader won't return either a local name, a namespace prefix or a namespace URI for <i>xmlns:fnord</i>.</p>
<p>This might be changed in the future following the W3C suggestion <a href="http://www.w3.org/2000/xmlns/">http://www.w3.org/2000/xmlns/</a> to associate <i>xmlns</i> with the namespace <i>http://www.w3.org/2000/xmlns</i>.</p>
<p>As the SAX2 standard suggests, <a href="qxmlsimplereader.html">QXmlSimpleReader</a> defaults to having <i>http://xml.org/sax/features/namespaces</i> set to true and <i>http://xml.org/sax/features/namespace-prefixes</i> set to false. When changing this behavior using <a href="qxmlsimplereader.html#setFeature">QXmlSimpleReader.setFeature</a>() note that the combination of both features set to false is illegal.</p>
<a name="summary" />
<h5>Summary</h5>
<p><a href="qxmlsimplereader.html">QXmlSimpleReader</a> implements the following behavior:</p>
<p><table align="center" border="0" cellpadding="2" cellspacing="1">
<tr bgcolor="#a2c511" valign="top"><th>(namespaces, namespace-prefixes)</th><th>Namespace prefix and local part</th><th>Qualified names</th><th>Prefix mapping</th><th>xmlns attributes</th></tr>
<tr bgcolor="#f0f0f0" valign="top"><td>(true, false)</td><td>Yes</td><td>Yes*</td><td>Yes</td><td>No</td></tr>
<tr bgcolor="#e0e0e0" valign="top"><td>(true, true)</td><td>Yes</td><td>Yes</td><td>Yes</td><td>Yes</td></tr>
<tr bgcolor="#f0f0f0" valign="top"><td>(false, true)</td><td>No*</td><td>Yes</td><td>No*</td><td>Yes</td></tr>
<tr bgcolor="#e0e0e0" valign="top"><td>(false, false)</td><td colspan="4">Illegal</td></tr>
</table></p>
<p>The behavior of the entries marked with an asterisk (*) is not specified by SAX.</p>
<a name="properties" />
<h4>Properties</h4>
<p>Properties are a more general concept. They have a unique name, represented as an URI, but their value is <tt>void*</tt>. Thus nearly anything can be used as a property value. This concept involves some danger, though: there is no means of ensuring type-safety; the user must take care that they pass the right type. Properties are useful if a reader supports special handler classes.</p>
<p>The URIs used for features and properties often look like URLs, e.g. <tt>http://xml.org/sax/features/namespace</tt>. This does not mean that the data required is at this address. It is simply a way of defining unique names.</p>
<p>Anyone can define and use new SAX2 properties for their readers. Property support is not mandatory.</p>
<p>To set or query properties the following functions are provided: <a href="qxmlreader.html#setProperty">QXmlReader.setProperty</a>(), <a href="qxmlreader.html#property">QXmlReader.property</a>() and <a href="qxmlreader.html#hasProperty">QXmlReader.hasProperty</a>().</p>
<a name="dom" /><a name="the-qt-dom-classes" />
<h3>The Qt DOM Classes</h3>
<a name="domintro" /><a name="introduction-to-dom" />
<h4>Introduction to DOM</h4>
<p>DOM provides an interface to access and change the content and structure of an XML file. It makes a hierarchical view of the document (a tree view). Thus -- in contrast to the SAX2 interface -- an object model of the document is resident in memory after parsing which makes manipulation easy.</p>
<p>All DOM nodes in the document tree are subclasses of <a href="qdomnode.html">QDomNode</a>. The document itself is represented as a <a href="qdomdocument.html">QDomDocument</a> object.</p>
<p>Here are the available node classes and their potential child classes:</p>
<ul>
<li><a href="qdomdocument.html">QDomDocument</a>: Possible children are<ul>
<li><a href="qdomelement.html">QDomElement</a> (at most one)</li>
<li><a href="qdomprocessinginstruction.html">QDomProcessingInstruction</a></li>
<li><a href="qdomcomment.html">QDomComment</a></li>
<li><a href="qdomdocumenttype.html">QDomDocumentType</a></li>
</ul>
</li>
<li><a href="qdomdocumentfragment.html">QDomDocumentFragment</a>: Possible children are<ul>
<li><a href="qdomelement.html">QDomElement</a></li>
<li><a href="qdomprocessinginstruction.html">QDomProcessingInstruction</a></li>
<li><a href="qdomcomment.html">QDomComment</a></li>
<li><a href="qdomtext.html">QDomText</a></li>
<li><a href="qdomcdatasection.html">QDomCDATASection</a></li>
<li><a href="qdomentityreference.html">QDomEntityReference</a></li>
</ul>
</li>
<li><a href="qdomdocumenttype.html">QDomDocumentType</a>: No children</li>
<li><a href="qdomentityreference.html">QDomEntityReference</a>: Possible children are<ul>
<li><a href="qdomelement.html">QDomElement</a></li>
<li><a href="qdomprocessinginstruction.html">QDomProcessingInstruction</a></li>
<li><a href="qdomcomment.html">QDomComment</a></li>
<li><a href="qdomtext.html">QDomText</a></li>
<li><a href="qdomcdatasection.html">QDomCDATASection</a></li>
<li><a href="qdomentityreference.html">QDomEntityReference</a></li>
</ul>
</li>
<li><a href="qdomelement.html">QDomElement</a>: Possible children are<ul>
<li><a href="qdomelement.html">QDomElement</a></li>
<li><a href="qdomtext.html">QDomText</a></li>
<li><a href="qdomcomment.html">QDomComment</a></li>
<li><a href="qdomprocessinginstruction.html">QDomProcessingInstruction</a></li>
<li><a href="qdomcdatasection.html">QDomCDATASection</a></li>
<li><a href="qdomentityreference.html">QDomEntityReference</a></li>
</ul>
</li>
<li><a href="qdomattr.html">QDomAttr</a>: Possible children are<ul>
<li><a href="qdomtext.html">QDomText</a></li>
<li><a href="qdomentityreference.html">QDomEntityReference</a></li>
</ul>
</li>
<li><a href="qdomprocessinginstruction.html">QDomProcessingInstruction</a>: No children</li>
<li><a href="qdomcomment.html">QDomComment</a>: No children</li>
<li><a href="qdomtext.html">QDomText</a>: No children</li>
<li><a href="qdomcdatasection.html">QDomCDATASection</a>: No children</li>
<li><a href="qdomentity.html">QDomEntity</a>: Possible children are<ul>
<li><a href="qdomelement.html">QDomElement</a></li>
<li><a href="qdomprocessinginstruction.html">QDomProcessingInstruction</a></li>
<li><a href="qdomcomment.html">QDomComment</a></li>
<li><a href="qdomtext.html">QDomText</a></li>
<li><a href="qdomcdatasection.html">QDomCDATASection</a></li>
<li><a href="qdomentityreference.html">QDomEntityReference</a></li>
</ul>
</li>
<li><a href="qdomnotation.html">QDomNotation</a>: No children</li>
</ul>
<p>With <a href="qdomnodelist.html">QDomNodeList</a> and <a href="qdomnamednodemap.html">QDomNamedNodeMap</a> two collection classes are provided: <a href="qdomnodelist.html">QDomNodeList</a> is a list of nodes, and <a href="qdomnamednodemap.html">QDomNamedNodeMap</a> is used to handle unordered sets of nodes (often used for attributes).</p>
<p>The <a href="qdomimplementation.html">QDomImplementation</a> class allows the user to query features of the DOM implementation.</p>
<p>To get started please refer to the <a href="qdomdocument.html">QDomDocument</a> documentation.</p>
<a name="namespaces" /><a name="an-introduction-to-namespaces" />
<h3>An Introduction to Namespaces</h3>
<p>Parts of the Qt XML module documentation assume that you are familiar with XML namespaces. Here we present a brief introduction; skip to <a href="#namespacesconventions">Qt XML documentation conventions</a> if you already know this material.</p>
<p>Namespaces are a concept introduced into XML to allow a more modular design. With their help data processing software can easily resolve naming conflicts in XML documents.</p>
<p>Consider the following example:</p>
<pre>&#160;   &lt;document&gt;
    &lt;book&gt;
      &lt;title&gt;Practical XML&lt;/title&gt;
      &lt;author title="Ms" name="Eris Kallisti"/&gt;
      &lt;chapter&gt;
        &lt;title&gt;A Namespace Called fnord&lt;/title&gt;
      &lt;/chapter&gt;
    &lt;/book&gt;
    &lt;/document&gt;</pre>
<p>Here we find three different uses of the name <i>title</i>. If you wish to process this document you will encounter problems because each of the <i>titles</i> should be displayed in a different manner -- even though they have the same name.</p>
<p>The solution would be to have some means of identifying the first occurrence of <i>title</i> as the title of a book, i.e. to use the <i>title</i> element of a book namespace to distinguish it from, for example, the chapter title, e.g.:</p>
<pre>&#160;   &lt;book:title&gt;Practical XML&lt;/book:title&gt;</pre>
<p><i>book</i> in this case is a <i>prefix</i> denoting the namespace.</p>
<p>Before we can apply a namespace to element or attribute names we must declare it.</p>
<p>Namespaces are URIs like <i>http://trolltech.com/fnord/book/</i>. This does not mean that data must be available at this address; the URI is simply used to provide a unique name.</p>
<p>We declare namespaces in the same way as attributes; strictly speaking they <i>are</i> attributes. To make for example <i>http://trolltech.com/fnord/</i> the document's default XML namespace <i>xmlns</i> we write</p>
<pre>&#160;   xmlns="http://trolltech.com/fnord/"</pre>
<p>To distinguish the <i>http://trolltech.com/fnord/book/</i> namespace from the default, we must supply it with a prefix:</p>
<pre>&#160;   xmlns:book="http://trolltech.com/fnord/book/"</pre>
<p>A namespace that is declared like this can be applied to element and attribute names by prepending the appropriate prefix and a ":" delimiter. We have already seen this with the <i>book:title</i> element.</p>
<p>Element names without a prefix belong to the default namespace. This rule does not apply to attributes: an attribute without a prefix does not belong to any of the declared XML namespaces at all. Attributes always belong to the "traditional" namespace of the element in which they appear. A "traditional" namespace is not an XML namespace, it simply means that all attribute names belonging to one element must be different. Later we will see how to assign an XML namespace to an attribute.</p>
<p>Due to the fact that attributes without prefixes are not in any XML namespace there is no collision between the attribute <i>title</i> (that belongs to the <i>author</i> element) and for example the <i>title</i> element within a <i>chapter</i>.</p>
<p>Let's clarify this with an example:</p>
<pre>&#160;   &lt;document xmlns:book = 'http://trolltech.com/fnord/book/'
              xmlns      = 'http://trolltech.com/fnord/' &gt;
    &lt;book&gt;
      &lt;book:title&gt;Practical XML&lt;/book:title&gt;
      &lt;book:author xmlns:fnord = 'http://trolltech.com/fnord/'
                   title="Ms"
                   fnord:title="Goddess"
                   name="Eris Kallisti"/&gt;
      &lt;chapter&gt;
        &lt;title&gt;A Namespace Called fnord&lt;/title&gt;
      &lt;/chapter&gt;
    &lt;/book&gt;
    &lt;/document&gt;</pre>
<p>Within the <i>document</i> element we have two namespaces declared. The default namespace <i>http://trolltech.com/fnord/</i> applies to the <i>book</i> element, the <i>chapter</i> element, the appropriate <i>title</i> element and of course to <i>document</i> itself.</p>
<p>The <i>book:author</i> and <i>book:title</i> elements belong to the namespace with the URI <i>http://trolltech.com/fnord/book/</i>.</p>
<p>The two <i>book:author</i> attributes <i>title</i> and <i>name</i> have no XML namespace assigned. They are only members of the "traditional" namespace of the element <i>book:author</i>, meaning that for example two <i>title</i> attributes in <i>book:author</i> are forbidden.</p>
<p>In the above example we circumvent the last rule by adding a <i>title</i> attribute from the <i>http://trolltech.com/fnord/</i> namespace to <i>book:author</i>: the <i>fnord:title</i> comes from the namespace with the prefix <i>fnord</i> that is declared in the <i>book:author</i> element.</p>
<p>Clearly the <i>fnord</i> namespace has the same namespace URI as the default namespace. So why didn't we simply use the default namespace we'd already declared? The answer is quite complex:</p>
<ul>
<li>attributes without a prefix don't belong to any XML namespace at all, not even to the default namespace;</li>
<li>additionally omitting the prefix would lead to a <i>title-title</i> clash;</li>
<li>writing it as <i>xmlns:title</i> would declare a new namespace with the prefix <i>title</i> instead of applying the default <i>xmlns</i> namespace.</li>
</ul>
<p>With the Qt XML classes elements and attributes can be accessed in two ways: either by refering to their qualified names consisting of the namespace prefix and the "real" name (or <i>local</i> name) or by the combination of local name and namespace URI.</p>
<p>More information on XML namespaces can be found at <a href="http://www.w3.org/TR/REC-xml-names/">http://www.w3.org/TR/REC-xml-names/</a>.</p>
<a name="namespacesconventions" /><a name="conventions-used-in-the-qt-xml-documentation" />
<h4>Conventions Used in the Qt XML Documentation</h4>
<p>The following terms are used to distinguish the parts of names within the context of namespaces:</p>
<ul>
<li>The <i>qualified name</i> is the name as it appears in the document. (In the above example <i>book:title</i> is a qualified name.)</li>
<li>A <i>namespace prefix</i> in a qualified name is the part to the left of the ":". (<i>book</i> is the namespace prefix in <i>book:title</i>.)</li>
<li>The <i>local part</i> of a name (also refered to as the <i>local name</i>) appears to the right of the ":". (Thus <i>title</i> is the local part of <i>book:title</i>.)</li>
<li>The <i>namespace URI</i> ("Uniform Resource Identifier") is a unique identifier for a namespace. It looks like a URL (e.g. <i>http://trolltech.com/fnord/</i> ) but does not require data to be accessible by the given protocol at the named address.</li>
</ul>
<p>Elements without a ":" (like <i>chapter</i> in the example) do not have a namespace prefix. In this case the local part and the qualified name are identical (i.e. <i>chapter</i>).</p>
<address><hr /><div align="center"><table border="0" cellspacing="0" width="100%"><tr class="address"><td align="left" width="25%">PyQt&#160;4.10.3 for X11</td><td align="center" width="50%">Copyright &#169; <a href="http://www.riverbankcomputing.com">Riverbank&#160;Computing&#160;Ltd</a> and <a href="http://www.qtsoftware.com">Nokia</a> 2012</td><td align="right" width="25%">Qt&#160;4.8.5</td></tr></table></div></address></body></html>