Example #1
0
void FileWriter::writeElementChilds(const QDomElement &AParent)
{
	QDomNode node = AParent.firstChild();
	while (!node.isNull())
	{
		if (node.isElement())
		{
			QDomElement elem = node.toElement();
			if (elem.tagName() != "thread")
			{
				FXmlWriter->writeStartElement(elem.tagName());

				QString elemNs = elem.namespaceURI();
				if (!elemNs.isEmpty() && elem.parentNode().namespaceURI()!=elemNs)
					FXmlWriter->writeAttribute("xmlns",elem.namespaceURI());

				QDomNamedNodeMap attrMap = elem.attributes();
				for (uint i=0; i<attrMap.length(); i++)
				{
					QDomNode attrNode = attrMap.item(i);
					FXmlWriter->writeAttribute(attrNode.nodeName(), attrNode.nodeValue());
				}

				writeElementChilds(elem);
				FXmlWriter->writeEndElement();
			}
		}
		else if (node.isCharacterData())
		{
			FXmlWriter->writeCharacters(node.toCharacterData().data());
		}

		node = node.nextSibling();
	}
}
Example #2
0
QWidget* FormModule::createWidgetFromUI(QWidget* parent, const QString& xml)
{
    QUiLoader loader;

    QDomDocument doc("mydocument");
    doc.setContent(xml.toUtf8());

    QDomNodeList strings=doc.elementsByTagName("string");
    int i=strings.size();
    while(--i>=0)
    {
        QDomElement e=strings.at(i).toElement();
        QString i18nd=e.attribute("comment").isEmpty()?QObject::tr(e.text().toUtf8()):QObject::tr(e.text().toUtf8(),e.attribute("comment").toUtf8());
        if (i18nd==e.text())
            continue;
        QDomNode n = e.firstChild();
        while (!n.isNull())
        {
            QDomNode nn=n.nextSibling();
            if (n.isCharacterData())
                e.removeChild(n);
            n = nn;
        }
        e.appendChild(e.ownerDocument().createTextNode(i18nd));
    }

    QByteArray ba = doc.toByteArray();
    QBuffer buffer(&ba);
    buffer.open(QIODevice::ReadOnly);

    QWidget* widget = loader.load(&buffer, parent);
    if( widget && parent && parent->layout() )
        parent->layout()->addWidget(widget);
    return widget;
}
Example #3
0
bool QDomNodeProto:: isCharacterData() const
{
  QDomNode *item = qscriptvalue_cast<QDomNode*>(thisObject());
  if (item)
    return item->isCharacterData();
  return false;
}
Example #4
0
QString XMLWork::innerXml(QDomElement &element)
{
    QString inner;
    for (QDomNode n = element.firstChild(); !n.isNull(); n = n.nextSibling())
        if (n.isCharacterData())
            inner += n.toCharacterData().data();
        else if (n.isElement()) {
            QDomElement e = n.toElement();
            inner += "<" + e.tagName() + ">" + innerXml(e) + "</" + e.tagName() + ">";
        }
    return inner;
}