Редактирование: Qt:Документация 4.3.2/qtxml
Материал из Wiki.crossplatform.ru
Внимание: Вы не представились системе. Ваш IP-адрес будет записан в историю изменений этой страницы.
ПРЕДУПРЕЖДЕНИЕ: Длина этой страницы составляет 50 килобайт. Страницы, размер которых приближается к 32 КБ или превышает это значение, могут неверно отображаться в некоторых браузерах. Пожалуйста, рассмотрите вариант разбиения страницы на меньшие части.
Правка может быть отменена. Пожалуйста, просмотрите сравнение версий, чтобы убедиться, что это именно те изменения, которые вас интересуют, и нажмите «Записать страницу», чтобы изменения вступили в силу.
Текущая версия | Ваш текст | ||
Строка 146: | Строка 146: | ||
Разделы: | Разделы: | ||
+ | |||
*[[#configuring-the-build-process | Конфигурирование процесса сборки]] | *[[#configuring-the-build-process | Конфигурирование процесса сборки]] | ||
*[[#the-qtxml-stream-classes | Классы потока QtXml]] | *[[#the-qtxml-stream-classes | Классы потока QtXml]] | ||
Строка 153: | Строка 154: | ||
**[[#namespace-support-via-features | Поддержка пространства имен]] | **[[#namespace-support-via-features | Поддержка пространства имен]] | ||
***[[#summary | Итоги]] | ***[[#summary | Итоги]] | ||
+ | |||
**[[#properties | Свойства]] | **[[#properties | Свойства]] | ||
+ | |||
*[[#the-qt-dom-classes | Классы Qt DOM]] | *[[#the-qt-dom-classes | Классы Qt DOM]] | ||
**[[#introduction-to-dom | Введение в DOM]] | **[[#introduction-to-dom | Введение в DOM]] | ||
+ | |||
*[[#an-introduction-to-namespaces | Введение в пространство имен]] | *[[#an-introduction-to-namespaces | Введение в пространство имен]] | ||
**[[#conventions-used-in-the-qt-xml-documentation | Соглашения, используемые в документации Qt XML]] | **[[#conventions-used-in-the-qt-xml-documentation | Соглашения, используемые в документации Qt XML]] | ||
Строка 161: | Строка 165: | ||
<div id="configuring-the-build-process"></div> | <div id="configuring-the-build-process"></div> | ||
===Конфигурирование процесса сборки=== | ===Конфигурирование процесса сборки=== | ||
+ | |||
Приложения, использующие классы Qt XML, должны быть собраны вместе с модулем QtXml. Следующее объявление в <tt>qmake</tt> файла проекта гарантирует, что приложение скомпилируется и отредактируется (linked) соответствующим образом: | Приложения, использующие классы Qt XML, должны быть собраны вместе с модулем QtXml. Следующее объявление в <tt>qmake</tt> файла проекта гарантирует, что приложение скомпилируется и отредактируется (linked) соответствующим образом: | ||
<source lang="cpp-qt"> QT += xml</source> | <source lang="cpp-qt"> QT += xml</source> | ||
Строка 167: | Строка 172: | ||
===Классы потока QtXml=== | ===Классы потока QtXml=== | ||
+ | |||
[[Qt:Документация 4.3.2/qxmlstreamreader | QXmlStreamReader]] и [[Qt:Документация 4.3.2/qxmlstreamwriter | QXmlStreamWriter]] это два новых класса, появившихся начиная с версии Qt 4.3. Потоковый модуль чтения представляет XML документ как поток токенов (tokens). Это отличие от SAX, т.к. SAX приложения обеспечивают обработку поступающих событий XML от парсера, тогда как [[Qt:Документация 4.3.2/qxmlstreamreader | QXmlStreamReader]] передача осуществляется циклически, втягивая токены из модуля чтения, когда они требуются. Данный подход, основанный на втягивании, предоставляет возможность строить парсеры с рекурсивной обработкой, позволяя разделить код, выполняющий синтаксический анализ XML, на различные методы и классы. | [[Qt:Документация 4.3.2/qxmlstreamreader | QXmlStreamReader]] и [[Qt:Документация 4.3.2/qxmlstreamwriter | QXmlStreamWriter]] это два новых класса, появившихся начиная с версии Qt 4.3. Потоковый модуль чтения представляет XML документ как поток токенов (tokens). Это отличие от SAX, т.к. SAX приложения обеспечивают обработку поступающих событий XML от парсера, тогда как [[Qt:Документация 4.3.2/qxmlstreamreader | QXmlStreamReader]] передача осуществляется циклически, втягивая токены из модуля чтения, когда они требуются. Данный подход, основанный на втягивании, предоставляет возможность строить парсеры с рекурсивной обработкой, позволяя разделить код, выполняющий синтаксический анализ XML, на различные методы и классы. | ||
Строка 296: | Строка 302: | ||
<div id="sax2-features"></div> | <div id="sax2-features"></div> | ||
- | ==== | + | ====SAX2 Features==== |
- | + | 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 ''http://xml.org/sax/features/namespace-prefixes''. | |
- | + | The Qt SAX2 implementation can report whether the reader has particular functionality using the [[Qt:Документация 4.3.2/qxmlreader#hasFeature | QXmlReader::hasFeature]]() function. Available features can be tested with [[Qt:Документация 4.3.2/qxmlreader#feature | QXmlReader::feature]](), and switched on or off using [[Qt:Документация 4.3.2/qxmlreader#setFeature | QXmlReader::setFeature]](). | |
- | + | Consider the example | |
<source lang="cpp-qt"> <document xmlns:book = 'http://trolltech.com/fnord/book/' | <source lang="cpp-qt"> <document xmlns:book = 'http://trolltech.com/fnord/book/' | ||
xmlns = 'http://trolltech.com/fnord/' ></source> | xmlns = 'http://trolltech.com/fnord/' ></source> | ||
- | + | A reader that does not support the ''http://xml.org/sax/features/namespace-prefixes'' feature would report the element name ''document'' but not its attributes ''xmlns:book'' and ''xmlns'' with their values. A reader with the feature ''http://xml.org/sax/features/namespace-prefixes'' reports the namespace attributes if the [[Qt:Документация 4.3.2/qxmlreader#feature | feature]] is switched on. | |
- | + | Other features include ''http://xml.org/sax/features/namespace'' (namespace processing, implies ''http://xml.org/sax/features/namespace-prefixes'') and ''http://xml.org/sax/features/validation'' (the ability to report validation errors). | |
- | + | Whilst SAX2 leaves it to the user to define and implement whatever features are required, support for ''http://xml.org/sax/features/namespace'' (and thus ''http://xml.org/sax/features/namespace-prefixes'') is mandantory. The [[Qt:Документация 4.3.2/qxmlsimplereader | QXmlSimpleReader]] implementation of [[Qt:Документация 4.3.2/qxmlreader | QXmlReader]], supports them, and can do namespace processing. | |
- | [[Qt:Документация 4.3.2/qxmlsimplereader | QXmlSimpleReader]] | + | [[Qt:Документация 4.3.2/qxmlsimplereader | QXmlSimpleReader]] is not validating, so it does not support ''http://xml.org/sax/features/validation''. |
<div id="namespace-support-via-features"></div> | <div id="namespace-support-via-features"></div> | ||
+ | ====Namespace Support via Features==== | ||
- | + | 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 ''http://xml.org/sax/features/namespaces'' and ''http://xml.org/sax/features/namespace-prefixes'' features. | |
- | + | They influence the reporting behavior in the following way: | |
- | + | #Namespace prefixes and local parts of elements and attributes can be reported. | |
+ | #The qualified names of elements and attributes are reported. | ||
+ | #[[Qt:Документация 4.3.2/qxmlcontenthandler#startPrefixMapping | QXmlContentHandler::startPrefixMapping]]() and [[Qt:Документация 4.3.2/qxmlcontenthandler#endPrefixMapping | QXmlContentHandler::endPrefixMapping]]() are called by the reader. | ||
+ | #Attributes that declare namespaces (i.e. the attribute ''xmlns'' and attributes starting with ''xmlns:'') are reported. | ||
- | + | Consider the following element: | |
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
<source lang="cpp-qt"> <author xmlns:fnord = 'http://trolltech.com/fnord/' | <source lang="cpp-qt"> <author xmlns:fnord = 'http://trolltech.com/fnord/' | ||
title="Ms" | title="Ms" | ||
fnord:title="Goddess" | fnord:title="Goddess" | ||
name="Eris Kallisti"/></source> | name="Eris Kallisti"/></source> | ||
- | + | With ''http://xml.org/sax/features/namespace-prefixes'' set to true the reader will report four attributes; but with the ''namespace-prefixes'' feature set to false only three, with the ''xmlns:fnord'' attribute defining a namespace being "invisible" to the reader. | |
- | + | The ''http://xml.org/sax/features/namespaces'' feature is responsible for reporting local names, namespace prefixes and URIs. With ''http://xml.org/sax/features/namespaces'' set to true the parser will report ''title'' as the local name of the ''fnord:title'' attribute, ''fnord'' being the namespace prefix and ''http://trolltech.com/fnord/'' as the namespace URI. When ''http://xml.org/sax/features/namespaces'' is false none of them are reported. | |
- | + | In the current implementation the Qt XML classes follow the definition that the prefix ''xmlns'' itself isn't associated with any namespace at all (see [http://www.w3.org/TR/1999/REC-xml-names-19990114/#ns-using http://www.w3.org/TR/1999/REC-xml-names-19990114/#ns-using]). Therefore even with ''http://xml.org/sax/features/namespaces'' and ''http://xml.org/sax/features/namespace-prefixes'' both set to true the reader won't return either a local name, a namespace prefix or a namespace URI for ''xmlns:fnord''. | |
- | + | This might be changed in the future following the W3C suggestion [http://www.w3.org/2000/xmlns/ http://www.w3.org/2000/xmlns/] to associate ''xmlns'' with the namespace ''http://www.w3.org/2000/xmlns''. | |
- | + | As the SAX2 standard suggests, [[Qt:Документация 4.3.2/qxmlsimplereader | QXmlSimpleReader]] defaults to having ''http://xml.org/sax/features/namespaces'' set to true and ''http://xml.org/sax/features/namespace-prefixes'' set to false. When changing this behavior using [[Qt:Документация 4.3.2/qxmlsimplereader#setFeature | QXmlSimpleReader::setFeature]]() note that the combination of both features set to false is illegal. | |
<div id="summary"></div> | <div id="summary"></div> | ||
- | ===== | + | =====Summary===== |
- | [[Qt:Документация 4.3.2/qxmlsimplereader | QXmlSimpleReader]] | + | [[Qt:Документация 4.3.2/qxmlsimplereader | QXmlSimpleReader]] implements the following behavior: |
Строка 348: | Строка 353: | ||
|- valign="top" class="qt-style" | | |- valign="top" class="qt-style" | | ||
!(namespaces, namespace-prefixes) | !(namespaces, namespace-prefixes) | ||
- | ! | + | !Namespace prefix and local part |
- | ! | + | !Qualified names |
- | ! | + | !Prefix mapping |
- | ! | + | !xmlns attributes |
|- valign="top" class="odd" | | |- valign="top" class="odd" | | ||
|(true, false) | |(true, false) | ||
Строка 375: | Строка 380: | ||
|} | |} | ||
- | + | The behavior of the entries marked with an asterisk (*) is not specified by SAX. | |
<div id="properties"></div> | <div id="properties"></div> | ||
- | |||
====Свойства==== | ====Свойства==== | ||