Qt 4.8
qxsdinstancereader.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtXmlPatterns module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include "qxsdinstancereader_p.h"
43 
45 
46 using namespace QPatternist;
47 
49  : m_context(context)
50  , m_model(model->iterate(model->root(QXmlNodeModelIndex()), QXmlNodeModelIndex::AxisChild))
51 {
52 }
53 
55 {
57 }
58 
60 {
61  m_model.next();
62 
68  }
69 }
70 
72 {
74 }
75 
77 {
79 }
80 
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 }
96 
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 }
112 
114 {
115  return m_model.name();
116 }
117 
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 }
139 
141 {
142  return m_cachedAttributes.contains(name);
143 }
144 
146 {
148 
149  return m_cachedAttributes.value(name);
150 }
151 
153 {
154  return m_cachedAttributes.keys().toSet();
155 }
156 
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 }
175 
177 {
178  return m_cachedItem;
179 }
180 
182 {
183  return m_cachedAttributeItems.value(name);
184 }
185 
187 {
188  return m_cachedSourceLocation;
189 }
190 
192 {
193  return index.namespaceBindings();
194 }
195 
The QXmlNodeModelIndex class identifies a node in an XML node model subclassed from QAbstractXmlNodeM...
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
QSet< T > toSet() const
Returns a QSet object with the data contained in this QList.
Definition: qset.h:309
NamespaceCode LocalNameCode
Definition: qxmlname.h:84
bool isNull() const
Returns true if this QXmlNodeModelIndex is a default constructed value, otherwise false...
#define it(className, varName)
QXmlNodeModelIndex index() const
qint16 NamespaceCode
Definition: qxmlname.h:82
QXmlItem attributeItem(const QXmlName &name) const
The QXmlItem class contains either an XML node or an atomic value.
QSourceLocation sourceLocation() const
virtual NamePool::Ptr namePool() const
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...
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
QVector< QXmlName > namespaceBindings() const
Definition: qitem_p.h:499
bool contains(const Key &key) const
Returns true if the hash contains an item with the key; otherwise returns false.
Definition: qhash.h:872
QXmlName convertToQName(const QString &name) const
const T value(const Key &key) const
Returns the value associated with the key.
Definition: qhash.h:606
virtual QHash< QXmlName, QXmlItem > attributeItems()
QXmlName::PrefixCode allocatePrefix(const QString &prefix)
Definition: qnamepool_p.h:214
QHash< QXmlName, QString > m_cachedAttributes
QXmlName::LocalNameCode allocateLocalName(const QString &ln)
Definition: qnamepool_p.h:208
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
QString left(int n) const Q_REQUIRED_RESULT
Returns a substring that contains the n leftmost characters of the string.
Definition: qstring.cpp:3664
QHash< QXmlName, QXmlItem > m_cachedAttributeItems
QSet< QXmlName > attributeNames() const
The QAbstractXmlNodeModel class is an abstract base class for modeling non-XML data to look like XML ...
The namespace for the internal API of QtXmlPatterns.
The QSourceLocation class identifies a location in a resource by URI, line, and column.
int indexOf(QChar c, int from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.cpp:2838
virtual Event next()
Advances this AbstractXmlPullProvider, and returns the new event.
Definition: qpullbridge.cpp:73
QXmlName::NamespaceCode namespaceForPrefix(const QXmlName::PrefixCode prefix) const
Definition: qitem_p.h:504
virtual QHash< QXmlName, QString > attributes()
If the current() is Element, the attributes of the element are returned, an empty list of attributes ...
const QAbstractXmlNodeModel * model() const
Returns the QAbstractXmlNodeModel that this node index refers to.
XsdInstanceReader(const QAbstractXmlNodeModel *model, const XsdSchemaContext::Ptr &context)
QString attribute(const QXmlName &name) const
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
QString & append(QChar c)
Definition: qstring.cpp:1777
Represents an item in the XPath 2.0 Data Model.
Definition: qitem_p.h:182
bool hasAttribute(const QXmlName &name) const
virtual QXmlName name() const
If the current event is StartElement, EndElement, ProcessingInstruction, Attribute, or Namespace, the node&#39;s name is returned.
QSourceLocation sourceLocation() const
virtual Event current() const
Returns the event that next() returned the last time it was called.
quint16 index
QXmlNodeModelIndex toNodeModelIndex() const
If this QXmlItem represents a node, it returns the item as a QXmlNodeModelIndex.
QList< Key > keys() const
Returns a list containing all the keys in the hash, in an arbitrary order.
Definition: qhash.h:648
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
NodeKind kind() const
Definition: qitem_p.h:471
QVector< QXmlName > namespaceBindings(const QXmlNodeModelIndex &index) const
NamespaceCode PrefixCode
Definition: qxmlname.h:83