<?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>QXmlName Class Reference</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">  </td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a> · <a href="classes.html"><font color="#004faf">All Classes</font></a> · <a href="modules.html"><font color="#004faf">Modules</font></a></td></table><h1 align="center">QXmlName Class Reference<br /><sup><sup>[<a href="qtxmlpatterns.html">QtXmlPatterns</a> module]</sup></sup></h1><p>The QXmlName class represents the name of an XML node, in an efficient, namespace-aware way. <a href="#details">More...</a></p> <h3>Methods</h3><ul><li><div class="fn" /><b><a href="qxmlname.html#QXmlName">__init__</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qxmlname.html#QXmlName-2">__init__</a></b> (<i>self</i>, QXmlNamePool <i>namePool</i>, QString <i>localName</i>, QString <i>namespaceUri</i> = QString(), QString <i>prefix</i> = QString())</li><li><div class="fn" /><b><a href="qxmlname.html#QXmlName-3">__init__</a></b> (<i>self</i>, QXmlName)</li><li><div class="fn" />bool <b><a href="qxmlname.html#isNull">isNull</a></b> (<i>self</i>)</li><li><div class="fn" />QString <b><a href="qxmlname.html#localName">localName</a></b> (<i>self</i>, QXmlNamePool <i>query</i>)</li><li><div class="fn" />QString <b><a href="qxmlname.html#namespaceUri">namespaceUri</a></b> (<i>self</i>, QXmlNamePool <i>query</i>)</li><li><div class="fn" />QString <b><a href="qxmlname.html#prefix">prefix</a></b> (<i>self</i>, QXmlNamePool <i>query</i>)</li><li><div class="fn" />QString <b><a href="qxmlname.html#toClarkName">toClarkName</a></b> (<i>self</i>, QXmlNamePool <i>query</i>)</li></ul><h3>Static Methods</h3><ul><li><div class="fn" />QXmlName <b><a href="qxmlname.html#fromClarkName">fromClarkName</a></b> (QString <i>clarkName</i>, QXmlNamePool <i>namePool</i>)</li><li><div class="fn" />bool <b><a href="qxmlname.html#isNCName">isNCName</a></b> (QString <i>candidate</i>)</li></ul><h3>Special Methods</h3><ul><li><div class="fn" />bool <b><a href="qxmlname.html#__eq__">__eq__</a></b> (<i>self</i>, QXmlName <i>other</i>)</li><li><div class="fn" />int <b><a href="qxmlname.html#__hash__">__hash__</a></b> (<i>self</i>)</li><li><div class="fn" />bool <b><a href="qxmlname.html#__ne__">__ne__</a></b> (<i>self</i>, QXmlName <i>other</i>)</li></ul><a name="details" /><hr /><h2>Detailed Description</h2><p>The QXmlName class represents the name of an XML node, in an efficient, namespace-aware way.</p> <p>QXmlName represents the name of an XML node in a way that is both efficient and safe for comparing names. Normally, an XML node represents an XML element or attribute, but QXmlName can also represent the names of other kinds of nodes, e.g., <a href="qabstractxmlreceiver.html#processingInstruction">QAbstractXmlReceiver.processingInstruction</a>() and <a href="qabstractxmlreceiver.html#namespaceBinding">QAbstractXmlReceiver.namespaceBinding</a>().</p> <p>The name of an XML node has three components: The <i>namespace URI</i>, the <i>local name</i>, and the <i>prefix</i>. To see what these refer to in XML, consider the following snippet.</p> <pre class="cpp"> <book xmlns:dc='http://purl.org/dc/elements/1.1' xmlns='http://example.com/MyDefault'> <dc:title>Mobey Dick</dc:title> ... </book> </pre> <p>For the element named <i>book</i>, <a href="qxmlname.html#localName">localName</a>() returns <i>book</i>, <a href="qxmlname.html#namespaceUri">namespaceUri</a>() returns <i>http://example.com/MyDefault</i>, and <a href="qxmlname.html#prefix">prefix</a>() returns an empty string. For the element named <i>title</i>, <a href="qxmlname.html#localName">localName</a>() returns <i>title</i>, <a href="qxmlname.html#namespaceUri">namespaceUri</a>() returns <i>http://purl.org/dc/elements/1.1</i>, and <a href="qxmlname.html#prefix">prefix</a>() returns <i>dc</i>.</p> <p>To ensure that operations with QXmlName are efficient, e.g., copying names and comparing them, each instance of QXmlName is associated with a <a href="qxmlnamepool.html">name pool</a>, which must be specified at QXmlName construction time. The three components of the QXmlName, i.e., the namespace URI, the local name, and the prefix, are stored in the name pool mapped to identifiers so they can be shared. For this reason, the only way to create a valid instance of QXmlName is to use the class constructor, where the <a href="qxmlnamepool.html">name pool</a>, local name, namespace URI, and prefix must all be specified.</p> <p>Note that QXmlName's default constructor constructs a null instance. It is typically used for allocating unused entries in collections of QXmlName.</p> <p>A side effect of associating each instance of QXmlName with a <a href="qxmlnamepool.html">name pool</a> is that each instance of QXmlName is tied to the <a href="qxmlnamepool.html">QXmlNamePool</a> with which it was created. However, the QXmlName class does not keep track of the name pool, so all the accessor functions, e.g., <a href="qxmlname.html#namespaceUri">namespaceUri</a>(), <a href="qxmlname.html#prefix">prefix</a>(), <a href="qxmlname.html#localName">localName</a>(), and <a href="qxmlname.html#toClarkName">toClarkName</a>() require that the correct name pool be passed to them. Failure to provide the correct name pool to these accessor functions results in undefined behavior.</p> <p>Note that a <a href="qxmlnamepool.html">name pool</a> is <i>not</i> an XML namespace. One <a href="qxmlnamepool.html">name pool</a> can represent instances of QXmlName from different XML namespaces, and the instances of QXmlName from one XML namespace can be distributed over multiple <a href="qxmlnamepool.html">name pools</a>.</p> <a id="comparing-qxmlnames" name="comparing-qxmlnames" /><a id="comparing-qxmlnames" name="comparing-qxmlnames" /> <h3>Comparing QXmlNames</h3> <p>To determine what a QXmlName refers to, the <i>namespace URI</i> and the <i>local name</i> are used. The <i>prefix</i> is not used because the prefix is simply a shorthand name for use in place of the normally much longer namespace URI. Nor is the prefix used in name comparisons. For example, the following two element nodes represent the same element and compare equal.</p> <pre class="cpp"> <svg xmlns="http://www.w3.org/2000/svg"/> </pre> <pre class="cpp"> <x:svg xmlns:x="http://www.w3.org/2000/svg"/> </pre> <p>Although the second name has the prefix <i>x</i>, the two names compare equal as instances of QXmlName, because the prefix is not used in the comparison.</p> <p>A local name can never be an empty string, although the prefix and namespace URI can. If the prefix is not empty, the namespace URI cannot be empty. Local names and prefixes must be valid <a href="http://www.w3.org/TR/REC-xml-names/#NT-NCName">NCNames</a>, e.g., <i>abc.def</i> or <i>abc123</i>.</p> <p>QXmlName represents what is sometimes called an <i>expanded QName</i>, or simply a QName.</p> <hr /><h2>Method Documentation</h2><h3 class="fn"><a name="QXmlName" />QXmlName.__init__ (<i>self</i>)</h3><p>Constructs an uninitialized <a href="qxmlname.html">QXmlName</a>. To build a valid <a href="qxmlname.html">QXmlName</a>, you normally use the other constructor, which takes a <a href="qxmlnamepool.html">name pool</a>, namespace URI, local name, and prefix as parameters. But you can also use this constructor to build a null <a href="qxmlname.html">QXmlName</a> and then assign an existing <a href="qxmlname.html">QXmlName</a> to it.</p> <p><b>See also</b> <a href="qxmlname.html#isNull">isNull</a>().</p> <h3 class="fn"><a name="QXmlName-2" />QXmlName.__init__ (<i>self</i>, <a href="qxmlnamepool.html">QXmlNamePool</a> <i>namePool</i>, QString <i>localName</i>, QString <i>namespaceUri</i> = QString(), QString <i>prefix</i> = QString())</h3><p>Constructs a <a href="qxmlname.html">QXmlName</a> instance that inserts <i>localName</i>, <i>namespaceURI</i> and <i>prefix</i> into <i>namePool</i> if they aren't already there. The accessor functions <a href="qxmlname.html#namespaceUri">namespaceUri</a>(), <a href="qxmlname.html#prefix">prefix</a>(), <a href="qxmlname.html#localName">localName</a>(), and <a href="qxmlname.html#toClarkName">toClarkName</a>() must be passed the <i>namePool</i> used here, so the <i>namePool</i> must remain in scope while the accessor functions might be used. However, two instances can be compared with <i>==</i> or <i>!=</i> and copied without the <i>namePool</i>.</p> <p>The user guarantees that the string components are valid for a QName. In particular, the local name, and the prefix (if present), must be valid <a href="http://www.w3.org/TR/REC-xml-names/#NT-NCName">NCNames</a>. The function <a href="qxmlname.html#isNCName">isNCName</a>() can be used to test validity of these names. The namespace URI should be an absolute URI. <a href="qurl.html#isRelative">QUrl.isRelative</a>() can be used to test whether the namespace URI is relative or absolute. Finally, providing a prefix is not valid when no namespace URI is provided.</p> <p><i>namePool</i> is not copied. Nor is the reference to it retained in this instance. This constructor inserts the three strings into <i>namePool</i>.</p> <h3 class="fn"><a name="QXmlName-3" />QXmlName.__init__ (<i>self</i>, <a href="qxmlname.html">QXmlName</a>)</h3><h3 class="fn"><a name="fromClarkName" /><a href="qxmlname.html">QXmlName</a> QXmlName.fromClarkName (QString <i>clarkName</i>, <a href="qxmlnamepool.html">QXmlNamePool</a> <i>namePool</i>)</h3><p>Converts <i>clarkName</i> into a <a href="qxmlname.html">QXmlName</a>, inserts into <i>namePool</i>, and returns it.</p> <p>A clark name is a way to present a full QName with only one string, where the namespace cannot contain braces. Here are a couple of examples:</p> <table class="generic"> <thead> <tr class="qt-style"> <th>Clark Name</th> <th>Description</th> </tr> </thead> <tr class="odd" valign="top"> <td><tt>html</tt></td> <td>The local name <tt>html</tt>, in no namespace</td> </tr> <tr class="even" valign="top"> <td><tt>http://www.w3.org/1999/xhtml</tt>html</td> <td>The local name <tt>html</tt>, in the XHTML namespace</td> </tr> <tr class="odd" valign="top"> <td><tt>http://www.w3.org/1999/xhtml</tt>my:html</td> <td>The local name <tt>html</tt>, in the XHTML namespace, with the prefix <tt>my</tt></td> </tr> </table> <p>If the namespace contains braces, the returned value is either invalid or has undefined content.</p> <p>If <i>clarkName</i> is an invalid name, a default constructed <a href="qxmlname.html">QXmlName</a> is returned.</p> <p>This function was introduced in Qt 4.5.</p> <p><b>See also</b> <a href="qxmlname.html#toClarkName">toClarkName</a>().</p> <h3 class="fn"><a name="isNCName" />bool QXmlName.isNCName (QString <i>candidate</i>)</h3><p>Returns true if <i>candidate</i> is an <tt>NCName</tt>. An <tt>NCName</tt> is a string that can be used as a name in XML and <a href="xmlprocessing.html">XQuery</a>, e.g., the prefix or local name in an element or attribute, or the name of a variable.</p> <p><b>See also</b> <a href="http://www.w3.org/TR/REC-xml-names/#NT-NCName">Namespaces in XML 1.0 (Second Edition), [4] NCName</a>.</p> <h3 class="fn"><a name="isNull" />bool QXmlName.isNull (<i>self</i>)</h3><p>Returns true if this <a href="qxmlname.html">QXmlName</a> is not initialized with a valid combination of <i>namespace URI</i>, <i>local name</i>, and <i>prefix</i>.</p> <p>A valid local name is always required. The prefix and namespace URI can be empty, but if the prefix is not empty, the namespace URI must not be empty. Local names and prefixes must be valid <a href="http://www.w3.org/TR/REC-xml-names/#NT-NCName">NCNames</a>, e.g., <i>abc.def</i> or <i>abc123</i>.</p> <h3 class="fn"><a name="localName" />QString QXmlName.localName (<i>self</i>, <a href="qxmlnamepool.html">QXmlNamePool</a> <i>query</i>)</h3><p>Returns the local name.</p> <p>Note that for efficiency, the local name string is not stored in the <a href="qxmlname.html">QXmlName</a> but in the <a href="qxmlnamepool.html">QXmlNamePool</a> that was passed to the constructor. Hence, that same <i>namePool</i> must be passed to this function, so it can be used for looking up the local name.</p> <h3 class="fn"><a name="namespaceUri" />QString QXmlName.namespaceUri (<i>self</i>, <a href="qxmlnamepool.html">QXmlNamePool</a> <i>query</i>)</h3><p>Returns the namespace URI.</p> <p>Note that for efficiency, the namespace URI string is not stored in the <a href="qxmlname.html">QXmlName</a> but in the <a href="qxmlnamepool.html">QXmlNamePool</a> that was passed to the constructor. Hence, that same <i>namePool</i> must be passed to this function, so it can be used for looking up the namespace URI.</p> <h3 class="fn"><a name="prefix" />QString QXmlName.prefix (<i>self</i>, <a href="qxmlnamepool.html">QXmlNamePool</a> <i>query</i>)</h3><p>Returns the prefix.</p> <p>Note that for efficiency, the prefix string is not stored in the <a href="qxmlname.html">QXmlName</a> but in the <a href="qxmlnamepool.html">QXmlNamePool</a> that was passed to the constructor. Hence, that same <i>namePool</i> must be passed to this function, so it can be used for looking up the prefix.</p> <h3 class="fn"><a name="toClarkName" />QString QXmlName.toClarkName (<i>self</i>, <a href="qxmlnamepool.html">QXmlNamePool</a> <i>query</i>)</h3><p>Returns this <a href="qxmlname.html">QXmlName</a> formatted as a Clark Name. For example, if the local name is <tt>html</tt>, the prefix is <tt>x</tt>, and the namespace URI is <tt>http://www.w3.org/1999/xhtml/</tt>, then the Clark Name returned is:</p> <pre class="cpp"> {http:<span class="comment">//www.w3.org/1999/xhtml/}x:html.</span> </pre> <p>If the local name is <i>MyWidget</i> and the namespace is empty, the Clark Name returned is:</p> <pre class="cpp"> MyWidget </pre> <p>Note that for efficiency, the namespace URI, local name, and prefix strings are not stored in the <a href="qxmlname.html">QXmlName</a> but in the <a href="qxmlnamepool.html">QXmlNamePool</a> that was passed to the constructor. Hence, that same <i>namePool</i> must be passed to this function, so it can be used for looking up the three string components.</p> <p>This function can be useful for debugging.</p> <p><b>See also</b> <a href="http://www.jclark.com/xml/xmlns.htm">XML Namespaces, James Clark</a> and <a href="qxmlname.html#fromClarkName">fromClarkName</a>().</p> <h3 class="fn"><a name="__eq__" />bool QXmlName.__eq__ (<i>self</i>, <a href="qxmlname.html">QXmlName</a> <i>other</i>)</h3><h3 class="fn"><a name="__hash__" />int QXmlName.__hash__ (<i>self</i>)</h3><h3 class="fn"><a name="__ne__" />bool QXmlName.__ne__ (<i>self</i>, <a href="qxmlname.html">QXmlName</a> <i>other</i>)</h3><address><hr /><div align="center"><table border="0" cellspacing="0" width="100%"><tr class="address"><td align="left" width="25%">PyQt 4.10.3 for X11</td><td align="center" width="50%">Copyright © <a href="http://www.riverbankcomputing.com">Riverbank Computing Ltd</a> and <a href="http://www.qtsoftware.com">Nokia</a> 2012</td><td align="right" width="25%">Qt 4.8.5</td></tr></table></div></address></body></html>