/*! \internal Treats \a outputItem as a node and calls the appropriate function, e.g., attribute() or comment(), depending on its QXmlNodeModelIndex::NodeKind. This is a helper function that subclasses can use to multiplex Nodes received via item(). */ void QAbstractXmlReceiver::sendAsNode(const QPatternist::Item &outputItem) { Q_ASSERT(outputItem); Q_ASSERT(outputItem.isNode()); const QXmlNodeModelIndex asNode = outputItem.asNode(); switch(asNode.kind()) { case QXmlNodeModelIndex::Attribute: { const QString &v = outputItem.stringValue(); attribute(asNode.name(), QStringRef(&v)); return; } case QXmlNodeModelIndex::Element: { startElement(asNode.name()); /* First the namespaces, then attributes, then the children. */ asNode.sendNamespaces(this); sendFromAxis<QXmlNodeModelIndex::AxisAttribute>(asNode); sendFromAxis<QXmlNodeModelIndex::AxisChild>(asNode); endElement(); return; } case QXmlNodeModelIndex::Text: { const QString &v = asNode.stringValue(); characters(QStringRef(&v)); return; } case QXmlNodeModelIndex::ProcessingInstruction: { processingInstruction(asNode.name(), outputItem.stringValue()); return; } case QXmlNodeModelIndex::Comment: { comment(outputItem.stringValue()); return; } case QXmlNodeModelIndex::Document: { startDocument(); sendFromAxis<QXmlNodeModelIndex::AxisChild>(asNode); endDocument(); return; } case QXmlNodeModelIndex::Namespace: Q_ASSERT_X(false, Q_FUNC_INFO, "Not implemented"); } Q_ASSERT_X(false, Q_FUNC_INFO, QString::fromLatin1("Unknown node type: %1").arg(asNode.kind()).toUtf8().constData()); }
void QAbstractXmlReceiver::sendAsNode(const Item &outputItem) { Q_ASSERT(outputItem); Q_ASSERT(outputItem.isNode()); const QXmlNodeModelIndex asNode = outputItem.asNode(); switch(asNode.kind()) { case QXmlNodeModelIndex::Attribute: { attribute(asNode.name(), outputItem.stringValue()); break; } case QXmlNodeModelIndex::Element: { startElement(asNode.name()); /* First the namespaces, then attributes, then the children. */ asNode.sendNamespaces(Ptr(const_cast<QAbstractXmlReceiver *>(this))); sendFromAxis<QXmlNodeModelIndex::AxisAttribute>(asNode); sendFromAxis<QXmlNodeModelIndex::AxisChild>(asNode); endElement(); break; } case QXmlNodeModelIndex::Text: { characters(outputItem.stringValue()); break; } case QXmlNodeModelIndex::ProcessingInstruction: { processingInstruction(asNode.name(), outputItem.stringValue()); break; } case QXmlNodeModelIndex::Comment: { comment(outputItem.stringValue()); break; } case QXmlNodeModelIndex::Document: { sendFromAxis<QXmlNodeModelIndex::AxisChild>(asNode); break; } case QXmlNodeModelIndex::Namespace: Q_ASSERT_X(false, Q_FUNC_INFO, "Not implemented"); } }
bool XsdInstanceReader::hasChildElement() const { const QXmlNodeModelIndex index = m_model.index(); QXmlNodeModelIndex::Iterator::Ptr it = index.model()->iterate(index, QXmlNodeModelIndex::AxisChild); QXmlNodeModelIndex currentIndex = it->next(); while (!currentIndex.isNull()) { if (currentIndex.kind() == QXmlNodeModelIndex::Element) return true; currentIndex = it->next(); } return false; }
void AccelTree::sendNamespaces(const QXmlNodeModelIndex &n, QAbstractXmlReceiver *const receiver) const { Q_ASSERT(n.kind() == QXmlNodeModelIndex::Element); const QXmlNodeModelIndex::Iterator::Ptr it(iterate(n, QXmlNodeModelIndex::AxisAncestorOrSelf)); QXmlNodeModelIndex next(it->next()); QVector<QXmlName::PrefixCode> alreadySent; while(!next.isNull()) { const PreNumber preNumber = toPreNumber(next); const QVector<QXmlName> &nss = namespaces.value(preNumber); /* This is by far the most common case. */ if(nss.isEmpty()) { next = it->next(); continue; } const int len = nss.count(); bool stopInheritance = false; for(int i = 0; i < len; ++i) { const QXmlName &name = nss.at(i); if(name.namespaceURI() == StandardNamespaces::StopNamespaceInheritance) { stopInheritance = true; continue; } if(!alreadySent.contains(name.prefix())) { alreadySent.append(name.prefix()); receiver->namespaceBinding(name); } } if(stopInheritance) break; else next = it->next(); } }
QString XsdInstanceReader::text() const { const QXmlNodeModelIndex index = m_model.index(); QXmlNodeModelIndex::Iterator::Ptr it = index.model()->iterate(index, QXmlNodeModelIndex::AxisChild); QString result; QXmlNodeModelIndex currentIndex = it->next(); while (!currentIndex.isNull()) { if (currentIndex.kind() == QXmlNodeModelIndex::Text) { result.append(Item(currentIndex).stringValue()); } currentIndex = it->next(); } return result; }
void AccelTree::copyNodeTo(const QXmlNodeModelIndex &node, QAbstractXmlReceiver *const receiver, const NodeCopySettings &settings) const { /* This code piece can be seen as a customized version of * QAbstractXmlReceiver::item/sendAsNode(). */ Q_ASSERT(receiver); Q_ASSERT(!node.isNull()); typedef QHash<QXmlName::PrefixCode, QXmlName::NamespaceCode> Binding; QStack<Binding> outputted; switch(node.kind()) { case QXmlNodeModelIndex::Element: { outputted.push(Binding()); /* Add the namespace for our element name. */ const QXmlName elementName(node.name()); receiver->startElement(elementName); if(!settings.testFlag(InheritNamespaces)) receiver->namespaceBinding(QXmlName(StandardNamespaces::StopNamespaceInheritance, 0, StandardPrefixes::StopNamespaceInheritance)); if(settings.testFlag(PreserveNamespaces)) node.sendNamespaces(receiver); else { /* Find the namespaces that we actually use and add them to outputted. These are drawn * from the element name, and the node's attributes. */ outputted.top().insert(elementName.prefix(), elementName.namespaceURI()); const QXmlNodeModelIndex::Iterator::Ptr attributes(iterate(node, QXmlNodeModelIndex::AxisAttribute)); QXmlNodeModelIndex attr(attributes->next()); while(!attr.isNull()) { const QXmlName &attrName = attr.name(); outputted.top().insert(attrName.prefix(), attrName.namespaceURI()); attr = attributes->next(); } Binding::const_iterator it(outputted.top().constBegin()); const Binding::const_iterator end(outputted.top().constEnd()); for(; it != end; ++it) receiver->namespaceBinding(QXmlName(it.value(), 0, it.key())); } /* Send the attributes of the element. */ { QXmlNodeModelIndex::Iterator::Ptr attributes(node.iterate(QXmlNodeModelIndex::AxisAttribute)); QXmlNodeModelIndex attribute(attributes->next()); while(!attribute.isNull()) { const QString &v = attribute.stringValue(); receiver->attribute(attribute.name(), QStringRef(&v)); attribute = attributes->next(); } } /* Send the children of the element. */ copyChildren(node, receiver, settings); receiver->endElement(); outputted.pop(); break; } case QXmlNodeModelIndex::Document: { /* We need to intercept and grab the elements of the document node, such * that we preserve/inherit preference applies to them. */ receiver->startDocument(); copyChildren(node, receiver, settings); receiver->endDocument(); break; } default: receiver->item(node); } }