📄 xml.html
字号:
a namespace URI for <em>xmlns:fnord</em>.<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 <em>xmlns</em> with the namespace <em>http://www.w3.org/2000/xmlns</em>. <p> As the SAX2 standard suggests <a href="qxmlsimplereader.html">QXmlSimpleReader</a> by default has<em>http://xml.org/sax/features/namespaces</em> set to TRUE and<em>http://xml.org/sax/features/namespace-prefixes</em> set to FALSE.When changing this behavior using <a href="qxmlreader.html#setFeature">QXmlSimpleReader::setFeature</a>() note that the combination of both features set toFALSE is illegal.<p> For a practical demonstration of how the two features affect the output of the reader run the <a href="tagreader-with-features-example.html">tagreader with features example.</a> <p> <a name="sax2NamespacesSummary"></a><h4> Summary</h4><a name="2-3-1"></a><p> <a href="qxmlsimplereader.html">QXmlSimpleReader</a> implements the following behavior:<p> <center><table cellpadding="4" cellspacing="2" border="0"><tr bgcolor="#a2c511"> <th valign="top">(namespaces, namespace-prefixes)<th valign="top">Namespace prefix and local part<th valign="top">Qualified names<th valign="top">Prefix mapping<th valign="top">xmlns attributes<tr bgcolor="#f0f0f0"> <td valign="top">(TRUE, FALSE) <td valign="top">Yes <td valign="top">Yes* <td valign="top">Yes <td valign="top">No<tr bgcolor="#d0d0d0"> <td valign="top">(TRUE, TRUE) <td valign="top">Yes <td valign="top">Yes <td valign="top">Yes <td valign="top">Yes<tr bgcolor="#f0f0f0"> <td valign="top">(FALSE, TRUE) <td valign="top">No* <td valign="top">Yes <td valign="top">No* <td valign="top">Yes<tr bgcolor="#d0d0d0"> <td valign="top">(FALSE, FALSE) <td valign="top" colspan="4" rowspan="1"> Illegal</table></center><p> For the entries marked with a "*", SAX does not require a particuliarbehavior.<p> <a name="sax2Properties"></a><h3> Properties</h3><a name="2-4"></a><p> Properties are a more general concept. They also have a unique name,represented as an URI, but their value is <tt>void*</tt>. Thus nearly everythingcan be used as a property value. This concept involves some danger,though: there are no means to ensure type-safety; the user must take carethat he or she passes the correct type. Properties are useful if a reader supportsspecial handler classes.<p> <p> The URIs used for features and properties often look like URLs, e.g. <a href="http://xml.org/sax/features/namespace">http://xml.org/sax/features/namespace</a>. This does not mean that whatsoeverdata is required at this address. It is simply a way to define unique names.<p> Everybody can define and use new SAX2 properties for his or herreaders. Property support is however notrequired.<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="sax2Reading"></a><h3> Further reading</h3><a name="2-5"></a><p> For a practical example on how to use the Qt SAX2 classes see the <a href="xml-sax-walkthrough.html">tagreader walkthrough.</a><p> More information about XML (e.g. <a href="xml.html#namespaces">namespaces</a>)can be found in the <a href="xml.html">introduction to the Qt XML module.</a><p> <a name="dom"></a><h2> The Qt DOM classes</h2><a name="3"></a><p> <a name="domIntro"></a><h3> Introduction to DOM</h3><a name="3-1"></a><p> DOM provides an interface to access and change the content and structure ofan XML file. It makes a hierarchical view of the document (tree) available with the root element of the XML file serving as its root. Thus -- in contrast to the SAX2 interface -- an object model of the document is resident in memory after parsing which makes manipulation easy. <p> In the Qt implementation of the DOM allnodes 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> Here are the available node classes and their potential children 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> <a href="qdomprocessinginstruction.html">QDomProcessingInstruction</a><li> <a href="qdomcomment.html">QDomComment</a><li> <a href="qdomdocumenttype.html">QDomDocumentType</a></ul><li> <a href="qdomdocumentfragment.html">QDomDocumentFragment</a>: Possible children are<ul><li> <a href="qdomelement.html">QDomElement</a><li> <a href="qdomprocessinginstruction.html">QDomProcessingInstruction</a><li> <a href="qdomcomment.html">QDomComment</a><li> <a href="qdomtext.html">QDomText</a><li> <a href="qdomcdatasection.html">QDomCDATASection</a><li> <a href="qdomentityreference.html">QDomEntityReference</a></ul><li> <a href="qdomdocumenttype.html">QDomDocumentType</a>: No children<li> <a href="qdomentityreference.html">QDomEntityReference</a>: Possible children are<ul><li> <a href="qdomelement.html">QDomElement</a><li> <a href="qdomprocessinginstruction.html">QDomProcessingInstruction</a><li> <a href="qdomcomment.html">QDomComment</a><li> <a href="qdomtext.html">QDomText</a><li> <a href="qdomcdatasection.html">QDomCDATASection</a><li> <a href="qdomentityreference.html">QDomEntityReference</a></ul><li> <a href="qdomelement.html">QDomElement</a>: Possible children are<ul><li> <a href="qdomelement.html">QDomElement</a><li> <a href="qdomtext.html">QDomText</a><li> <a href="qdomcomment.html">QDomComment</a><li> <a href="qdomprocessinginstruction.html">QDomProcessingInstruction</a><li> <a href="qdomcdatasection.html">QDomCDATASection</a><li> <a href="qdomentityreference.html">QDomEntityReference</a></ul><li> <a href="qdomattr.html">QDomAttr</a>: Possible children are<ul><li> <a href="qdomtext.html">QDomText</a><li> <a href="qdomentityreference.html">QDomEntityReference</a></ul><li> <a href="qdomprocessinginstruction.html">QDomProcessingInstruction</a>: No children<li> <a href="qdomcomment.html">QDomComment</a>: No children<li> <a href="qdomtext.html">QDomText</a>: No children<li> <a href="qdomcdatasection.html">QDomCDATASection</a>: No children<li> <a href="qdomentity.html">QDomEntity</a>: Possible children are<ul><li> <a href="qdomelement.html">QDomElement</a><li> <a href="qdomprocessinginstruction.html">QDomProcessingInstruction</a><li> <a href="qdomcomment.html">QDomComment</a><li> <a href="qdomtext.html">QDomText</a><li> <a href="qdomcdatasection.html">QDomCDATASection</a><li> <a href="qdomentityreference.html">QDomEntityReference</a></ul><li> <a href="qdomnotation.html">QDomNotation</a>: No children</ul><p> With <a href="qdomnodelist.html">QDomNodeList</a> and <a href="qdomnamednodemap.html">QDomNamedNodeMap</a> two <a href="collection.html#collection-classes">collection classes</a> are provided: <a href="qdomnodelist.html">QDomNodeList</a> is a list of nodeswhereas <a href="qdomnamednodemap.html">QDomNamedNodeMap</a> is used to handle unordered sets of nodes(often used for attributes).<p> The <a href="qdomimplementation.html">QDomImplementation</a> class allows the user to query features of theDOM implementation.<p> <h3> Further reading</h3><a name="3-2"></a><p> To get started please refer to the <a href="qdomdocument.html">QDomDocument</a> documentation thatdescribes basic usage.<p> <a name="namespaces"></a><h2> An introduction to namespaces</h2><a name="4"></a><p> Parts of the Qt XML module documentation assume that you arefamiliar with XML namespaces. Here we present a brief introduction;skip to <a href="#namespacesConventions">Qt XMLdocumentation conventions</a> 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><document><book> <title>Practical XML</title> <author title="Ms" name="Eris Kallisti"/> <chapter> <title>A Namespace Called fnord</title> </chapter></book></document></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 thefirst occurrence of <em>title</em> as the title of a book, i.e.to use the <em>title</em> element of abook namespace to distinguish it from for example the chapter title, e.g.:<pre><book:title>Practical XML</book:title></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 asattributes; 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 attributewithout 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 anyXML namespace there isno 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> Let's clarify matters with an example:<pre><document xmlns:book = 'http://trolltech.com/fnord/book/' xmlns = 'http://trolltech.com/fnord/' ><book> <book:title>Practical XML</book:title> <book:author xmlns:fnord = 'http://trolltech.com/fnord/' title="Ms" fnord:title="Goddess" name="Eris Kallisti"/> <chapter> <title>A Namespace Called fnord</title> </chapter></book></document></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> elementsbelong 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> attributesin <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 thedefault 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> additionally 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: eitherby refering to their qualified names consisting of the namespace prefixand the "real" name (or <em>local</em> name) orby 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> <a name="namespacesConventions"></a><h3> Conventions used in Qt XML documentation</h3><a name="4-1"></a><p> The following terms are used to distinguish the parts of names within the context ofnamespaces:<ul><li> The <em>qualified name</em>is the name as it appears in the document. (In the above example <em>book:title</em> is a qualified name.)<li> A <em>namespace prefix</em> in a qualified nameis the part to the left of the ":". (<em>book</em> is the namespace prefix in<em>book:title</em>.)<li> The <em>local part</em> of a name (also refered to as the <em>local name</em>) appearsto the right of the ":".(Thus <em>title</em> is the local part of <em>book:title</em>.)<li> The <em>namespace URI</em> ("Uniform Resource Identifier") is a uniqueidentifier for a namespace. It looks like a URL(e.g. <em>http://trolltech.com/fnord/</em> ) but does not requiredata 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 anamespace prefix. In this case the local part and the qualified nameare identical (i.e. <em>chapter</em>).<!-- eof --><p><address><hr><div align=center><table width=100% cellspacing=0 border=0><tr><td>Copyright © 2002 <a href="http://www.trolltech.com">Trolltech</a><td><a href="http://www.trolltech.com/trademarks.html">Trademarks</a><td align=right><div align=right>Qt version 3.0.5</div></table></div></address></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -