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

📄 xml.html

📁 QT 下载资料仅供参考
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><!-- /home/reggie/tmp/qt-3.0-reggie-5401/qt-x11-commercial-3.0.5/doc/xml.doc:36 --><html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>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: #ffffff; color: black; }--></style></head><body><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr bgcolor="#E5E5E5"><td valign=center> <a href="index.html"><font color="#004faf">Home</font></a> | <a href="classes.html"><font color="#004faf">All&nbsp;Classes</font></a> | <a href="mainclasses.html"><font color="#004faf">Main&nbsp;Classes</font></a> | <a href="annotated.html"><font color="#004faf">Annotated</font></a> | <a href="groups.html"><font color="#004faf">Grouped&nbsp;Classes</font></a> | <a href="functions.html"><font color="#004faf">Functions</font></a></td><td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>XML Module</h1> <p> This module is part of the <a href="editions.html">Qt Enterprise Edition</a>.<p> <!-- toc --><ul><li><a href="#1"> Overview of the XML architecture in Qt</a><li><a href="#2"> The Qt SAX2 classes</a><ul><li><a href="#2-1"> Introduction to SAX2</a><li><a href="#2-2"> Features</a><li><a href="#2-3"> Namespace support via features</a><ul><li><a href="#2-3-1"> Summary</a></ul><li><a href="#2-4"> Properties</a><li><a href="#2-5"> Further reading</a></ul><li><a href="#3"> The Qt DOM classes</a><ul><li><a href="#3-1"> Introduction to DOM</a><li><a href="#3-2"> Further reading</a></ul><li><a href="#4"> An introduction to namespaces</a><ul><li><a href="#4-1"> Conventions used in Qt XML documentation</a></ul></ul><!-- endtoc --><p> <a name="overview"></a><h2> Overview of the XML architecture in Qt</h2><a name="1"></a><p> 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> 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 underdevelopment. Furthermore the Qt implementation does not include theSAX1 compatibility classes present in the Java interface.<p> For an introduction to Qt's SAX2 classes see"<a href="#sax2">The Qt SAX2 classes</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="#dom">Qt DOM classes</a>.<p> Qt provides the following XML related classes:<p> <ul><li> <a href="qdomattr.html">QDomAttr</a> -- Represents one attribute of a <a href="qdomelement.html">QDomElement</a><li> <a href="qdomcdatasection.html">QDomCDATASection</a> -- Represents an XML CDATA section<li> <a href="qdomcharacterdata.html">QDomCharacterData</a> -- Represents a generic string in the DOM<li> <a href="qdomcomment.html">QDomComment</a> -- Represents an XML comment<li> <a href="qdomdocument.html">QDomDocument</a> -- The representation of an XML document<li> <a href="qdomdocumentfragment.html">QDomDocumentFragment</a> -- Tree of QDomNodes which is usually not a complete <a href="qdomdocument.html">QDomDocument</a><li> <a href="qdomdocumenttype.html">QDomDocumentType</a> -- The representation of the DTD in the document tree<li> <a href="qdomelement.html">QDomElement</a> -- Represents one element in the DOM tree<li> <a href="qdomentity.html">QDomEntity</a> -- Represents an XML entity<li> <a href="qdomentityreference.html">QDomEntityReference</a> -- Represents an XML entity reference<li> <a href="qdomimplementation.html">QDomImplementation</a> -- Information about the features of the DOM implementation<li> <a href="qdomnamednodemap.html">QDomNamedNodeMap</a> -- Collection of nodes that can be accessed by name<li> <a href="qdomnode.html">QDomNode</a> -- The base class for all nodes of the DOM tree<li> <a href="qdomnodelist.html">QDomNodeList</a> -- List of <a href="qdomnode.html">QDomNode</a> objects<li> <a href="qdomnotation.html">QDomNotation</a> -- Represents an XML notation<li> <a href="qdomprocessinginstruction.html">QDomProcessingInstruction</a> -- Represents an XML processing instruction<li> <a href="qdomtext.html">QDomText</a> -- Represents textual data in the parsed XML document<li> <a href="qxmlattributes.html">QXmlAttributes</a> -- XML attributes<li> <a href="qxmlcontenthandler.html">QXmlContentHandler</a> -- Interface to report logical content of XML data<li> <a href="qxmldeclhandler.html">QXmlDeclHandler</a> -- Interface to report declaration content of XML data<li> <a href="qxmldefaulthandler.html">QXmlDefaultHandler</a> -- Default implementation of all XML handler classes<li> <a href="qxmldtdhandler.html">QXmlDTDHandler</a> -- Interface to report DTD content of XML data<li> <a href="qxmlentityresolver.html">QXmlEntityResolver</a> -- Interface to resolve extern entities contained in XML data<li> <a href="qxmlerrorhandler.html">QXmlErrorHandler</a> -- Interface to report errors in XML data<li> <a href="qxmlinputsource.html">QXmlInputSource</a> -- The input data for the <a href="qxmlreader.html">QXmlReader</a> subclasses<li> <a href="qxmllexicalhandler.html">QXmlLexicalHandler</a> -- Interface to report lexical content of XML data<li> <a href="qxmllocator.html">QXmlLocator</a> -- The XML handler classes with information about the actual parsing position<li> <a href="qxmlnamespacesupport.html">QXmlNamespaceSupport</a> -- Helper class for XML readers which want to include namespace support<li> <a href="qxmlparseexception.html">QXmlParseException</a> -- Used to report errors with the <a href="qxmlerrorhandler.html">QXmlErrorHandler</a> interface<li> <a href="qxmlreader.html">QXmlReader</a> -- Interface for XML readers (i.e. for SAX2 parsers)<li> <a href="qxmlsimplereader.html">QXmlSimpleReader</a> -- Implementation of a simple XML reader (a SAX2 parser)</ul><p> <a name="sax2"></a><h2> The Qt SAX2 classes</h2><a name="2"></a><p> <a name="sax2Intro"></a><h3> Introduction to SAX2</h3><a name="2-1"></a><p> The SAX2 interface is an event-driven mechanism to provide the user withdocument information. "Event" in this context has nothing to do with theterm "event" you probably know from windowing systems; it means that theparser reports certain document information while parsing the document.These reported information is referred to as "event".<p> To make it less abstract consider the following example:<pre> &lt;quote&gt;To make it less abstract consider the following example:&lt;/quote&gt;</pre> <p> Whilst reading (a SAX2 parser is usually referred to as "reader") the above document three events would be triggered:<ol type=1><li> A start tag occurs (<tt>&lt;quote&gt;</tt>).<li> Character data (i.e. text) is found.<li> An end tag is parsed (<tt>&lt;/quote&gt;</tt>).</ol><p> Each time such an event occurs the parser reports it so that a suitable event handling routine can be invoked.<p> Whilst this is a fast and simple approach to read XML documentsmanipulation is difficult because data are not stored, simply handledand discarded serially. This is when the <a href="#dom">DOM interface</a> comes handy.<p> The Qt XML module provides anabstract class, <a href="qxmlreader.html">QXmlReader</a>, that defines the interface for potential SAX2 readers.At the moment Qt ships with one reader implementation, <a href="qxmlsimplereader.html">QXmlSimpleReader</a>.<p> The reader reports parsing events through special handler classes. In Qtthe following ones are available:<ul><li> <a href="qxmlcontenthandler.html">QXmlContentHandler</a>reports events related to the content of a document (e.g. the start tagor characters).<li> <a href="qxmldtdhandler.html">QXmlDTDHandler</a>reports events related to the DTD (e.g. notation declarations).<li> <a href="qxmlerrorhandler.html">QXmlErrorHandler</a>reports errors or warnings that occurred during parsing.<li> <a href="qxmlentityresolver.html">QXmlEntityResolver</a>reports external entities during parsing and allows the user to resolveexternal entities him- or herself instead of leaving it to the reader.<li> <a href="qxmldeclhandler.html">QXmlDeclHandler</a>reports further DTD related events (e.g. attribute declarations).Usually users are not interested in them, but under certain circumstancesthis class comes handy.<li> <a href="qxmllexicalhandler.html">QXmlLexicalHandler</a>reports events related to the lexical structure of the document(the beginning of the DTD, comments etc.). Occasionally thismight be useful.</ul><p> These classes are abstract classes describing the interface. The<a href="qxmldefaulthandler.html">QXmlDefaultHandler</a> class provides a "do nothing" default implementation forall of them. Therefore users need to overload only the<a href="qxmldefaulthandler.html">QXmlDefaultHandler</a> functions they are interested in. <p> To read input XML data a special class <a href="qxmlinputsource.html">QXmlInputSource</a> is used.<p> Apart from the already mentioned ones the following SAX2 support classes provide the user with useful functionality:<ul><li> <a href="qxmlattributes.html">QXmlAttributes</a>is used to pass attributes in a start element event.<li> <a href="qxmllocator.html">QXmlLocator</a>is used to obtain the actual parsing position of an event.<li> <a href="qxmlnamespacesupport.html">QXmlNamespaceSupport</a>is used to easily implement <a href="xml.html#namespaces">namespace</a>support for a reader.Note that namespaces do not change the parsing behavior. They are only reported through the handler.</ul><p> <a name="sax2Features"></a><h3> Features</h3><a name="2-2"></a><p> The behaviour of an XML reader depends on whether it supports certainoptional features or not. As an example a reader can have the feature "report attributes used for <a href="xml.html#namespaces">namespace</a> declarationsand 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 <em>http://xml.org/sax/features/namespace-prefixes</em>.<p> The Qt SAX2 implementation allows you to find out whether the reader has this ability using <a href="qxmlreader.html#hasFeature">QXmlReader::hasFeature</a>().If the return value is TRUE it is possible toturn the relevant feature on and off.To do this use <a href="qxmlreader.html#setFeature">QXmlReader::setFeature</a>(). Whether a supported featureis on or off (TRUE or FALSE) can be queried using  <a href="qxmlreader.html#feature">QXmlReader::feature</a>().<p> Consider the example <pre> &lt;document xmlns:book = 'http://trolltech.com/fnord/book/'          xmlns      = 'http://trolltech.com/fnord/' &gt;</pre> A reader not supporting the<em>http://xml.org/sax/features/namespace-prefixes</em> feature would clearlyreport the element name <em>document</em> but not its attributes <em>xmlns:book</em> and <em>xmlns</em>with their values. Areader with the feature <em>http://xml.org/sax/features/namespace-prefixes</em>reports the namespace attributes if <a href="qxmlreader.html#feature">QXmlReader::feature</a>() is TRUE and disregards them if the feature is FALSE.<p> Other features include <em>http://xml.org/sax/features/namespace</em> (namespace processing, implies <em>http://xml.org/sax/features/namespace-prefixes</em>) or<em>http://xml.org/sax/features/validation</em> (the ability to report validationerrors). <p> Whilst SAX2 leaves it to the user to define and implement whateverfeatures are required, support for <em>http://xml.org/sax/features/namespace</em>(and thus <em>http://xml.org/sax/features/namespace-prefixes</em>) ismandantory. Accordingly <a href="qxmlsimplereader.html">QXmlSimpleReader</a>, the implementationof <a href="qxmlreader.html">QXmlReader</a> that comes with the Qt XML module, supports both of them,and therefore can do namespace processing.<p> Being a non-validating parser <a href="qxmlsimplereader.html">QXmlSimpleReader</a> does not support <em>http://xml.org/sax/features/validation</em>and other features.<p> <a name="sax2Namespaces"></a><h3> Namespace support via features</h3><a name="2-3"></a><p> As we have seen in the <a href="#sax2Features">previous section</a>we can configure the behavior of the reader when it comes to namespaceprocessing. This is done by setting and unsetting the <em>http://xml.org/sax/features/namespaces</em> and<em>http://xml.org/sax/features/namespace-prefixes</em> features.<p> They influence the reporting behavior in the following way:<ol type=1><li> Namespace prefixes and local parts of elements and attributes can bereported.<li> The qualified names of elements and attributes are reported.<li> <a href="qxmlcontenthandler.html#startPrefixMapping">QXmlContentHandler::startPrefixMapping</a>() and <a href="qxmlcontenthandler.html#endPrefixMapping">QXmlContentHandler::endPrefixMapping</a>() are called by the reader.<li> Attributes that declare namespaces (i.e. the attribute <em>xmlns</em> andattributes starting with <em>xmlns</em>: ) are reported.</ol><p> Consider the following element:<p> <pre>&lt;author xmlns:fnord = 'http://trolltech.com/fnord/'             title="Ms"              fnord:title="Goddess"              name="Eris Kallisti"/&gt;</pre> <p> With <em>http://xml.org/sax/features/namespace-prefixes</em> set to TRUE the reader will report four attributes, with the <em>namespace-prefixes</em>feature set to FALSE only three: The <em>xmlns:fnord</em> attribute defininga namespace is then "unvisible" for the reader.<p> The <em>http://xml.org/sax/features/namespaces</em> feature on the other hand is responsible for reporting local names, namespace prefixes and -URIs.With <em>http://xml.org/sax/features/namespaces</em> set to TRUEthe parser will report <em>title</em> as the local name of <em>fnord:title</em>attribute, <em>fnord</em> being the namespace prefix and <em>http://trolltech.com/fnord/</em>as the namespace URI.When <em>http://xml.org/sax/features/namespaces</em> is FALSE none of them arereported.<p> In the current implementation the Qt XML classes follow the definitionthat the prefix <em>xmlns</em> 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 <em>http://xml.org/sax/features/namespaces</em> and<em>http://xml.org/sax/features/namespace-prefixes</em> both set to TRUEthe reader won't return either a local name, a namespace prefix or

⌨️ 快捷键说明

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