void XBELImportCommand::doExecute(const KBookmarkGroup &/*bkGroup*/) { // check if already open first??? KBookmarkManager *pManager = KBookmarkManager::managerForFile(m_fileName, QString()); QDomDocument doc = GlobalBookmarkManager::self()->mgr()->internalDocument(); // get the xbel QDomNode subDoc = pManager->internalDocument().namedItem("xbel").cloneNode(); if (subDoc.isProcessingInstruction()) subDoc = subDoc.nextSibling(); if (subDoc.isDocumentType()) subDoc = subDoc.nextSibling(); if (subDoc.nodeName() != "xbel") return; if (!folder().isEmpty()) { // transform into folder subDoc.toElement().setTagName("folder"); // clear attributes QStringList tags; for (int i = 0; i < subDoc.attributes().count(); i++) tags << subDoc.attributes().item(i).toAttr().name(); for (QStringList::const_iterator it = tags.constBegin(); it != tags.constEnd(); ++it) subDoc.attributes().removeNamedItem((*it)); subDoc.toElement().setAttribute("icon", m_icon); // give the folder a name QDomElement textElem = doc.createElement("title"); subDoc.insertBefore(textElem, subDoc.firstChild()); textElem.appendChild(doc.createTextNode(folder())); } // import and add it QDomNode node = doc.importNode(subDoc, true); if (!folder().isEmpty()) { GlobalBookmarkManager::self()->root().internalElement().appendChild(node); m_group = KBookmarkGroup(node.toElement()).address(); } else { QDomElement root = GlobalBookmarkManager::self()->root().internalElement(); QList<QDomElement> childList; QDomNode n = subDoc.firstChild().toElement(); while (!n.isNull()) { QDomElement e = n.toElement(); if (!e.isNull()) childList.append(e); n = n.nextSibling(); } QList<QDomElement>::Iterator it = childList.begin(); QList<QDomElement>::Iterator end = childList.end(); for (; it!= end ; ++it) root.appendChild((*it)); } }
bool QDomNodeProto:: isProcessingInstruction() const { QDomNode *item = qscriptvalue_cast<QDomNode*>(thisObject()); if (item) return item->isProcessingInstruction(); return false; }
void ReadAndWriteXML::parseEntry(const QDomElement &element, QTreeWidgetItem *parent, int parentLevel) { // item->setText(0, element.attribute("term")); QDomNode node = element.firstChild(); while (!node.isNull()) { //qDebug() << "DomParser::parseEntry node " << node.toElement().tagName(); // qDebug() << "DomParser::parseEntry parsing node " << node.nodeName(); if (node.isElement()) { //qDebug() << "DomParser::parseEntry "<< node.nodeName()<< " is element "; QTreeWidgetItem *childitem=new QTreeWidgetItem(parent, QStringList(QString("Type: %1").arg(node.nodeName()))); parseEntry(node.toElement(), childitem,++parentLevel); QString _attr=""; if (node.hasAttributes()) { childitem=new QTreeWidgetItem(childitem, QStringList(QString("Attributes node %1").arg(node.nodeName()))); parseAttribute(node.attributes(), childitem, parentLevel); } node = node.nextSibling(); continue; } if (node.isCDATASection()) { //qDebug() << "DomParser::parseEntry "<< node.nodeName()<< " is CDATASection --" << node.toText().data() << "--"; new QTreeWidgetItem(parent, QStringList(QString("Type: %1 Value: %2").arg(node.nodeName(),node.toText().data()))); node = node.nextSibling(); continue; } if (node.isComment()) { //qDebug() << "DomParser::parseEntry "<< node.nodeName()<< " is comment --" << node.toText().data() << "--"; new QTreeWidgetItem(parent, QStringList(QString("Type: %1 Value: %2").arg(node.nodeName(),node.toText().data()))); node = node.nextSibling(); continue; } if (node.isText()) { //qDebug() << "DomParser::parseEntry "<< node.nodeName()<< " text --" << node.toText().data() << "--"; new QTreeWidgetItem(parent, QStringList(QString("Type: %1 Value: %2").arg(node.nodeName(),node.toText().data()))); node = node.nextSibling(); continue; } if (node.isDocument()) { //qDebug() << "DomParser::parseEntry "<< node.nodeName()<< " is document "; QTreeWidgetItem *childitem=new QTreeWidgetItem(parent, QStringList(QString("Type: %1").arg(node.nodeName()))); parseEntry(node.toElement(), childitem,++parentLevel); node = node.nextSibling(); continue; } if (node.isDocumentType()) { qDebug() << "DomParser::parseEntry "<< node.nodeName()<< " is document type"; QTreeWidgetItem *childitem=new QTreeWidgetItem(parent, QStringList(QString("Type: %1").arg(node.nodeName()))); parseEntry(node.toElement(), childitem,++parentLevel); node = node.nextSibling(); continue; } if (node.isDocumentFragment()) { qDebug() << "DomParser::parseEntry "<< node.nodeName()<< " is document fragment"; QTreeWidgetItem *childitem=new QTreeWidgetItem(parent, QStringList(QString("Type: %1").arg(node.nodeName()))); parseEntry(node.toElement(), childitem,++parentLevel); node = node.nextSibling(); continue; } if (node.isEntity() || node.isEntityReference () || node.isNotation () || node.isProcessingInstruction ()) { qDebug() << "DomParser::parseEntry "<< node.nodeName()<< " is not supported"; node = node.nextSibling(); continue; } node = node.nextSibling(); } }