Qt 4.8
Public Types | Public Functions | Protected Functions | Protected Variables | Properties | List of all members
QPatternist::XsdInstanceReader Class Reference

The schema instance reader. More...

#include <qxsdinstancereader_p.h>

Inheritance diagram for QPatternist::XsdInstanceReader:
QPatternist::XsdValidatingInstanceReader

Public Types

typedef QExplicitlySharedDataPointer< XsdInstanceReaderPtr
 

Public Functions

 XsdInstanceReader (const QAbstractXmlNodeModel *model, const XsdSchemaContext::Ptr &context)
 

Protected Functions

bool atEnd () const
 
QString attribute (const QXmlName &name) const
 
QXmlItem attributeItem (const QXmlName &name) const
 
QSet< QXmlNameattributeNames () const
 
QXmlName convertToQName (const QString &name) const
 
bool hasAttribute (const QXmlName &name) const
 
bool hasChildElement () const
 
bool hasChildText () const
 
bool isEndElement () const
 
bool isStartElement () const
 
QXmlItem item () const
 
QXmlName name () const
 
QVector< QXmlNamenamespaceBindings (const QXmlNodeModelIndex &index) const
 
void readNext ()
 
QSourceLocation sourceLocation () const
 
QString text () const
 

Protected Variables

XsdSchemaContext::Ptr m_context
 

Properties

QHash< QXmlName, QXmlItemm_cachedAttributeItems
 
QHash< QXmlName, QStringm_cachedAttributes
 
QXmlItem m_cachedItem
 
QSourceLocation m_cachedSourceLocation
 
PullBridge m_model
 

Detailed Description

The schema instance reader.

This class reads in a xml instance document from a QAbstractXmlNodeModel and provides a QXmlStreamReader like interface with some additional context information.

Author
Tobias Koenig tobia.nosp@m.s.ko.nosp@m.enig@.nosp@m.noki.nosp@m.a.com

Definition at line 75 of file qxsdinstancereader_p.h.

Typedefs

◆ Ptr

Definition at line 78 of file qxsdinstancereader_p.h.

Constructors and Destructors

◆ XsdInstanceReader()

XsdInstanceReader::XsdInstanceReader ( const QAbstractXmlNodeModel model,
const XsdSchemaContext::Ptr context 
)

Creates a new instance reader that will read the data from the given model.

Parameters
modelThe model the data are read from.
contextThe context that is used for error reporting etc.

Definition at line 48 of file qxsdinstancereader.cpp.

49  : m_context(context)
51 {
52 }
The QXmlNodeModelIndex class identifies a node in an XML node model subclassed from QAbstractXmlNodeM...
virtual QExplicitlySharedDataPointer< QAbstractXmlForwardIterator< QXmlNodeModelIndex > > iterate(const QXmlNodeModelIndex &ni, QXmlNodeModelIndex::Axis axis) const
Performs navigation, starting from ni, by returning an QAbstractXmlForwardIterator that returns nodes...
virtual QXmlNodeModelIndex root(const QXmlNodeModelIndex &n) const =0
Returns the root node of the tree that contains the node whose index is n.

Functions

◆ atEnd()

bool XsdInstanceReader::atEnd ( ) const
protected

Returns true if the end of the document is reached, false otherwise.

Definition at line 54 of file qxsdinstancereader.cpp.

Referenced by QPatternist::XsdValidatingInstanceReader::read().

55 {
57 }
virtual Event current() const
Returns the event that next() returned the last time it was called.

◆ attribute()

QString XsdInstanceReader::attribute ( const QXmlName name) const
protected

Returns the attribute with the given name of the current node.

Definition at line 145 of file qxsdinstancereader.cpp.

Referenced by QPatternist::XsdValidatingInstanceReader::qNameAttribute(), QPatternist::XsdValidatingInstanceReader::validate(), QPatternist::XsdValidatingInstanceReader::validateElement(), and QPatternist::XsdValidatingInstanceReader::validateElementComplexType().

146 {
148 
149  return m_cachedAttributes.value(name);
150 }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
bool contains(const Key &key) const
Returns true if the hash contains an item with the key; otherwise returns false.
Definition: qhash.h:872
const T value(const Key &key) const
Returns the value associated with the key.
Definition: qhash.h:606
QHash< QXmlName, QString > m_cachedAttributes

◆ attributeItem()

QXmlItem XsdInstanceReader::attributeItem ( const QXmlName name) const
protected

Returns the QXmlItem for the attribute with the given name at the current position.

Definition at line 181 of file qxsdinstancereader.cpp.

Referenced by QPatternist::XsdValidatingInstanceReader::validateAttribute().

182 {
183  return m_cachedAttributeItems.value(name);
184 }
const T value(const Key &key) const
Returns the value associated with the key.
Definition: qhash.h:606
QHash< QXmlName, QXmlItem > m_cachedAttributeItems

◆ attributeNames()

QSet< QXmlName > XsdInstanceReader::attributeNames ( ) const
protected

Returns the list of attribute names of the current node.

Definition at line 152 of file qxsdinstancereader.cpp.

Referenced by QPatternist::XsdValidatingInstanceReader::validateElementComplexType(), and QPatternist::XsdValidatingInstanceReader::validateElementSimpleType().

153 {
154  return m_cachedAttributes.keys().toSet();
155 }
QSet< T > toSet() const
Returns a QSet object with the data contained in this QList.
Definition: qset.h:309
QHash< QXmlName, QString > m_cachedAttributes
QList< Key > keys() const
Returns a list containing all the keys in the hash, in an arbitrary order.
Definition: qhash.h:648

◆ convertToQName()

QXmlName XsdInstanceReader::convertToQName ( const QString name) const
protected

Converts a qualified name into a QXmlName according to the namespace mappings of the current node.

Definition at line 118 of file qxsdinstancereader.cpp.

Referenced by QPatternist::XsdValidatingInstanceReader::selectNodeSets(), QPatternist::XsdValidatingInstanceReader::validate(), and QPatternist::XsdValidatingInstanceReader::validateElement().

119 {
120  const int pos = name.indexOf(QLatin1Char(':'));
121 
122  QXmlName::PrefixCode prefixCode = 0;
123  QXmlName::NamespaceCode namespaceCode;
124  QXmlName::LocalNameCode localNameCode;
125  if (pos != -1) {
126  prefixCode = m_context->namePool()->allocatePrefix(name.left(pos));
127  namespaceCode = m_cachedItem.toNodeModelIndex().namespaceForPrefix(prefixCode);
128  localNameCode = m_context->namePool()->allocateLocalName(name.mid(pos + 1));
129  } else {
130  prefixCode = StandardPrefixes::empty;
131  namespaceCode = m_cachedItem.toNodeModelIndex().namespaceForPrefix(prefixCode);
132  if (namespaceCode == -1)
133  namespaceCode = StandardNamespaces::empty;
134  localNameCode = m_context->namePool()->allocateLocalName(name);
135  }
136 
137  return QXmlName(namespaceCode, localNameCode, prefixCode);
138 }
NamespaceCode LocalNameCode
Definition: qxmlname.h:84
qint16 NamespaceCode
Definition: qxmlname.h:82
virtual NamePool::Ptr namePool() const
QXmlName::PrefixCode allocatePrefix(const QString &prefix)
Definition: qnamepool_p.h:214
QXmlName::LocalNameCode allocateLocalName(const QString &ln)
Definition: qnamepool_p.h:208
QString left(int n) const Q_REQUIRED_RESULT
Returns a substring that contains the n leftmost characters of the string.
Definition: qstring.cpp:3664
int indexOf(QChar c, int from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.cpp:2838
QXmlName::NamespaceCode namespaceForPrefix(const QXmlName::PrefixCode prefix) const
Definition: qitem_p.h:504
QString mid(int position, int n=-1) const Q_REQUIRED_RESULT
Returns a string that contains n characters of this string, starting at the specified position index...
Definition: qstring.cpp:3706
The QXmlName class represents the name of an XML node, in an efficient, namespace-aware way...
Definition: qxmlname.h:58
QXmlNodeModelIndex toNodeModelIndex() const
If this QXmlItem represents a node, it returns the item as a QXmlNodeModelIndex.
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
NamespaceCode PrefixCode
Definition: qxmlname.h:83

◆ hasAttribute()

bool XsdInstanceReader::hasAttribute ( const QXmlName name) const
protected

Returns whether the current node has an attribute with the given name.

Definition at line 140 of file qxsdinstancereader.cpp.

Referenced by QPatternist::XsdValidatingInstanceReader::validate(), and QPatternist::XsdValidatingInstanceReader::validateElement().

141 {
142  return m_cachedAttributes.contains(name);
143 }
bool contains(const Key &key) const
Returns true if the hash contains an item with the key; otherwise returns false.
Definition: qhash.h:872
QHash< QXmlName, QString > m_cachedAttributes

◆ hasChildElement()

bool XsdInstanceReader::hasChildElement ( ) const
protected

Returns whether the current node has an element node among its children.

Definition at line 97 of file qxsdinstancereader.cpp.

Referenced by QPatternist::XsdValidatingInstanceReader::validateElement(), QPatternist::XsdValidatingInstanceReader::validateElementComplexType(), and QPatternist::XsdValidatingInstanceReader::validateElementSimpleType().

98 {
101 
102  QXmlNodeModelIndex currentIndex = it->next();
103  while (!currentIndex.isNull()) {
104  if (currentIndex.kind() == QXmlNodeModelIndex::Element)
105  return true;
106 
107  currentIndex = it->next();
108  }
109 
110  return false;
111 }
The QXmlNodeModelIndex class identifies a node in an XML node model subclassed from QAbstractXmlNodeM...
bool isNull() const
Returns true if this QXmlNodeModelIndex is a default constructed value, otherwise false...
#define it(className, varName)
QXmlNodeModelIndex index() const
The QExplicitlySharedDataPointer class represents a pointer to an explicitly shared object...
Definition: qshareddata.h:136
virtual QExplicitlySharedDataPointer< QAbstractXmlForwardIterator< QXmlNodeModelIndex > > iterate(const QXmlNodeModelIndex &ni, QXmlNodeModelIndex::Axis axis) const
Performs navigation, starting from ni, by returning an QAbstractXmlForwardIterator that returns nodes...
const QAbstractXmlNodeModel * model() const
Returns the QAbstractXmlNodeModel that this node index refers to.
quint16 index
NodeKind kind() const
Definition: qitem_p.h:471

◆ hasChildText()

bool XsdInstanceReader::hasChildText ( ) const
protected

Returns whether the current node has a text node among its children.

Definition at line 81 of file qxsdinstancereader.cpp.

Referenced by QPatternist::XsdValidatingInstanceReader::validateElement(), QPatternist::XsdValidatingInstanceReader::validateElementComplexType(), and QPatternist::XsdValidatingInstanceReader::validateElementSimpleType().

82 {
85 
86  QXmlNodeModelIndex currentIndex = it->next();
87  while (!currentIndex.isNull()) {
88  if (currentIndex.kind() == QXmlNodeModelIndex::Text)
89  return true;
90 
91  currentIndex = it->next();
92  }
93 
94  return false;
95 }
The QXmlNodeModelIndex class identifies a node in an XML node model subclassed from QAbstractXmlNodeM...
bool isNull() const
Returns true if this QXmlNodeModelIndex is a default constructed value, otherwise false...
#define it(className, varName)
QXmlNodeModelIndex index() const
The QExplicitlySharedDataPointer class represents a pointer to an explicitly shared object...
Definition: qshareddata.h:136
virtual QExplicitlySharedDataPointer< QAbstractXmlForwardIterator< QXmlNodeModelIndex > > iterate(const QXmlNodeModelIndex &ni, QXmlNodeModelIndex::Axis axis) const
Performs navigation, starting from ni, by returning an QAbstractXmlForwardIterator that returns nodes...
const QAbstractXmlNodeModel * model() const
Returns the QAbstractXmlNodeModel that this node index refers to.
quint16 index
NodeKind kind() const
Definition: qitem_p.h:471

◆ isEndElement()

bool XsdInstanceReader::isEndElement ( ) const
protected

Returns whether the current node is an end element.

Definition at line 76 of file qxsdinstancereader.cpp.

Referenced by QPatternist::XsdValidatingInstanceReader::read().

77 {
79 }
virtual Event current() const
Returns the event that next() returned the last time it was called.

◆ isStartElement()

bool XsdInstanceReader::isStartElement ( ) const
protected

Returns whether the current node is a start element.

Definition at line 71 of file qxsdinstancereader.cpp.

Referenced by QPatternist::XsdValidatingInstanceReader::read().

72 {
74 }
virtual Event current() const
Returns the event that next() returned the last time it was called.

◆ item()

QXmlItem XsdInstanceReader::item ( ) const
protected

◆ name()

QXmlName XsdInstanceReader::name ( ) const
protected

Returns the name of the current node.

Definition at line 113 of file qxsdinstancereader.cpp.

Referenced by QPatternist::XsdValidatingInstanceReader::anyType(), QPatternist::XsdValidatingInstanceReader::read(), QPatternist::XsdValidatingInstanceReader::selectNodeSets(), QPatternist::XsdValidatingInstanceReader::validate(), and QPatternist::XsdValidatingInstanceReader::validateAttributeWildcard().

114 {
115  return m_model.name();
116 }
virtual QXmlName name() const
If the current event is StartElement, EndElement, ProcessingInstruction, Attribute, or Namespace, the node&#39;s name is returned.

◆ namespaceBindings()

QVector< QXmlName > XsdInstanceReader::namespaceBindings ( const QXmlNodeModelIndex index) const
protected

Returns the namespace bindings for the given node model index.

Definition at line 191 of file qxsdinstancereader.cpp.

Referenced by QPatternist::XsdValidatingInstanceReader::validateAttribute(), QPatternist::XsdValidatingInstanceReader::validateElementComplexType(), and QPatternist::XsdValidatingInstanceReader::validateElementSimpleType().

192 {
193  return index.namespaceBindings();
194 }
QVector< QXmlName > namespaceBindings() const
Definition: qitem_p.h:499

◆ readNext()

void XsdInstanceReader::readNext ( )
protected

Reads the next node from the document.

Definition at line 59 of file qxsdinstancereader.cpp.

Referenced by QPatternist::XsdValidatingInstanceReader::read().

60 {
61  m_model.next();
62 
68  }
69 }
QXmlNodeModelIndex index() const
The QXmlItem class contains either an XML node or an atomic value.
QSourceLocation sourceLocation() const
virtual QHash< QXmlName, QXmlItem > attributeItems()
QHash< QXmlName, QString > m_cachedAttributes
QHash< QXmlName, QXmlItem > m_cachedAttributeItems
virtual Event next()
Advances this AbstractXmlPullProvider, and returns the new event.
Definition: qpullbridge.cpp:73
virtual QHash< QXmlName, QString > attributes()
If the current() is Element, the attributes of the element are returned, an empty list of attributes ...
virtual Event current() const
Returns the event that next() returned the last time it was called.

◆ sourceLocation()

QSourceLocation XsdInstanceReader::sourceLocation ( ) const
protected

◆ text()

QString XsdInstanceReader::text ( ) const
protected

Returns the concatenated text of all direct child text nodes.

Definition at line 157 of file qxsdinstancereader.cpp.

Referenced by QPatternist::XsdValidatingInstanceReader::validateElementComplexType(), and QPatternist::XsdValidatingInstanceReader::validateElementSimpleType().

158 {
161 
162  QString result;
163 
164  QXmlNodeModelIndex currentIndex = it->next();
165  while (!currentIndex.isNull()) {
166  if (currentIndex.kind() == QXmlNodeModelIndex::Text) {
167  result.append(Item(currentIndex).stringValue());
168  }
169 
170  currentIndex = it->next();
171  }
172 
173  return result;
174 }
The QXmlNodeModelIndex class identifies a node in an XML node model subclassed from QAbstractXmlNodeM...
bool isNull() const
Returns true if this QXmlNodeModelIndex is a default constructed value, otherwise false...
#define it(className, varName)
QXmlNodeModelIndex index() const
The QExplicitlySharedDataPointer class represents a pointer to an explicitly shared object...
Definition: qshareddata.h:136
The QString class provides a Unicode character string.
Definition: qstring.h:83
virtual QExplicitlySharedDataPointer< QAbstractXmlForwardIterator< QXmlNodeModelIndex > > iterate(const QXmlNodeModelIndex &ni, QXmlNodeModelIndex::Axis axis) const
Performs navigation, starting from ni, by returning an QAbstractXmlForwardIterator that returns nodes...
const QAbstractXmlNodeModel * model() const
Returns the QAbstractXmlNodeModel that this node index refers to.
QString & append(QChar c)
Definition: qstring.cpp:1777
Represents an item in the XPath 2.0 Data Model.
Definition: qitem_p.h:182
quint16 index
NodeKind kind() const
Definition: qitem_p.h:471

Properties

◆ m_cachedAttributeItems

QHash<QXmlName, QXmlItem> QPatternist::XsdInstanceReader::m_cachedAttributeItems
private

Definition at line 179 of file qxsdinstancereader_p.h.

Referenced by attributeItem(), and readNext().

◆ m_cachedAttributes

QHash<QXmlName, QString> QPatternist::XsdInstanceReader::m_cachedAttributes
private

Definition at line 178 of file qxsdinstancereader_p.h.

Referenced by attribute(), attributeNames(), hasAttribute(), and readNext().

◆ m_cachedItem

QXmlItem QPatternist::XsdInstanceReader::m_cachedItem
private

Definition at line 181 of file qxsdinstancereader_p.h.

Referenced by convertToQName(), item(), and readNext().

◆ m_cachedSourceLocation

QSourceLocation QPatternist::XsdInstanceReader::m_cachedSourceLocation
private

Definition at line 180 of file qxsdinstancereader_p.h.

Referenced by readNext(), and sourceLocation().

◆ m_context

XsdSchemaContext::Ptr QPatternist::XsdInstanceReader::m_context
protected

◆ m_model

PullBridge QPatternist::XsdInstanceReader::m_model
private

The documentation for this class was generated from the following files: