⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xml.html

📁 qtopiaphone英文帮助,用于初学者和开发人员,初学者可以用来学习,开发人员可以用来资料查询.
💻 HTML
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Qt Toolkit -  Qt XML Module</title><style type="text/css"><!--h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm; }a:link { color: #004faf; text-decoration: none }a:visited { color: #672967; text-decoration: none }body { background: white; color: black; }--></style></head><body bgcolor="#ffffff"><p><table width="100%"><tr><td><a href="index.html"><img width="100" height="100" src="qtlogo.png"alt="Home" border="0"><img width="100"height="100" src="face.png" alt="Home" border="0"></a><td valign="top"><div align="right"><img src="dochead.png" width="472" height="27"><br><a href="classes.html"><b>Classes</b></a>- <a href="annotated.html">Annotated</a>- <a href="hierarchy.html">Tree</a>- <a href="functions.html">Functions</a>- <a href="index.html">Home</a>- <a href="topicals.html"><b>Structure</b>  <font face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular" align="center" size=32>Qte</font></a></div></table><h1 align="center"> Qt XML Module</h1><br clear="all">The XML module provides a well-formed XML parser using the SAX2 (Simple API forXML) interface plus an implementation of the DOM Level 2 (Document ObjectModel).<p>This document assumes that you are familiar with the essentials of XML. Itprovides you with information on the XML module in Qtand explains some often neglected XML features that will help you make the best use of the Qt XML classes. <p>We will however not teach XML basics. If you wish to learn more about XML please refer to other sources,e.g. <a href="http://www.w3.org/XML/">http://www.w3.org/XML/</a>.<p><h2><a name="overview">Overview of the XML architecture in Qt</a></h2><p>The Qt XML Module provides two interfaces for XML: SAX2 and DOM Level 2.<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.megginson.com/SAX/">http://www.megginson.com/SAX/</a>.<p>Support for SAX2 filters and the reader factory are under development.Furthermore the Qt implementation does not include the SAX1 compatibility classes present in the Java interface. <p>For an introduction to Qt's SAX2 classes see"<a href="xml-sax.html">The Qt SAX2 implementation</a>". A code example is discussed in the "<a href="xml-sax-walkthrough.html">tagreaderwalkthrough</a>".<p>DOM Level 2 is a W3C Recommendation for XML interfaces that maps theconstituents of an XML document to a tree structure. Details and thespecification 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="xml-dom.html">Qt XML DOM overview</a>.<p><h2><a name="namespaces">An introduction to namespaces</a></h2><p>Parts of the Qt XML module documentation assume that you arefamiliar with XML namespaces. Here we present a brief introduction;skip to "Qt XMLdocumentation conventions" if you know this material.<p>Namespaces are a concept introduced into XML to allow a more modular design.With their help data processing software can easilyresolve naming conflicts in XML documents. <p>Consider the following example:<p><pre>&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 <em>title.</em> If you wishto process this document you will encounter problemsbecause each of the <em>titles</em> should be displayed in a different manner --even though they have the same name.<p>The solution would be to have some means of identifying the first occurence of <em>title</em> as the title of a book, i.e. to use the <em>title</em> element of a book namespace to distinguish it from for example the chapter title, e.g.:<pre>&lt;book:title&gt;Practical XML&lt;/book:title&gt;</pre><p><em>book</em> in this case isa <em>prefix</em> denoting the namespace.<p>Before we can apply anamespace to element or attribute names we must declare it.<p>Namespaces are URIs like <em>http://trolltech.com/fnord/book/.</em>This does not mean that data must be available at thisaddress; the URI is simply used to provide a unique name.<p>We declare namespaces in the same way as attributes; strictly speaking they <em>are</em> attributes. To make for example <em>http://trolltech.com/fnord/</em> the document'sdefault XML namespace <em>xmlns</em> we write<p><pre>xmlns="http://trolltech.com/fnord/"</pre><p>To distinguish the <em>http://trolltech.com/fnord/book/</em> namespacefrom the default, we have to supply it with a prefix:<p><pre>xmlns:book="http://trolltech.com/fnord/book/"</pre><p>A namespace that is declared like this can be appliedto element and attribute names by prepending the appropriateprefix and a ":" delimiter. We have already seen this withthe <em>book:title</em> element.<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 declaredXML namespaces at all.Attributes always belong to the "traditional" namespaceof the element in which they appear. A "traditional" namespaceis not an XML namespace, it simply means that all attribute namesbelonging to one element must be different. Later we will see howto assign an XML namespace to an attribute.<p>Due to the fact that attributes without prefixes are not in any XML namespace there is no collision between the attribute <em>title</em> (that belongs to the <em>author</em> element) and for example the <em>title</em> element within a <em>chapter.</em><p>Lets clarify matters with an example:<pre>&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 <em>document</em> element we have two namespaces declared.The default namespace <em>http://trolltech.com/fnord/</em> applies to the <em>book</em> element, the <em>chapter</em> element,the appropriate <em>title</em> element and of course to <em>document</em> itself.<p>The <em>book:author</em> and <em>book:title</em> elements belong to the namespace with theURI <em>http://trolltech.com/fnord/book/.</em><p>The two <em>book:author</em> attributes <em>title</em> and <em>name</em> have no XML namespaceassigned. They are only members of the "traditional" namespace of the element<em>book:author,</em> meaning that for example two <em>title</em> attributes in <em>book:author</em> are forbidden.<p>In the above example we circumvent the last rule by adding a <em>title</em>attribute from the <em>http://trolltech.com/fnord/</em> namespace to <em>book:author:</em> the <em>fnord:title</em> comes from the namespace with the prefix <em>fnord</em>that is declared in the <em>book:author</em> element. <p>Clearly the <em>fnord</em> namespace has the same namespace URI as thedefault namespace. So why didn't we simply use the default namespace we'd already declared? The answer is quite complex:<UL><LI>attributes without a prefix don't belong to any XML namespace at all,even not to the default namespace;<LI>additionaly omitting the prefix would lead to a <em>title-title</em> clash;<LI>writing it as <em>xmlns:title</em> would declare a new namespace withthe prefix <em>title</em> instead of applying the default <em>xmlns</em> namespace. </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 prefixand the "real" name (or <em>local</em> name) or by the combination of local name and namespace URI.<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><h2><a name="conventions">Conventions used in Qt XML documentation</a></h2><p>The following terms are used to distinguish the parts of names within the context ofnamespaces:<ul><li>The <i>qualified name</i>    is the name as it appears in the document. (In the above example <em>book:title</em> is a qualified name.)<li>A <i>namespace prefix</i> in a qualified name    is the part to the left of the ":".  (<em>book</em> is the namespace prefix in     <em>book:title.)</em><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 <em>title</em> is the local part of <em>book:title.)</em><li>The <I>namespace URI</I> ("Uniform Resource Identifier") is a unique    identifier for a namespace. It looks like a URL    (e.g. <em>http://trolltech.com/fnord/</em> ) but does not require     data to be accessible by the given protocol at the named address.</ul><p>Elements without a ":" (like <em>chapter</em> in the example) do not have a namespaceprefix. In this case the local part and the qualified name are identical (i.e. <em>chapter).</em><p><address><hr><div align="center"><table width="100%" cellspacing="0" border="0"><tr><td>Copyright 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -