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
QDomCharacterData QDomNodeProto:: toCharacterData() const
{
  QDomNode *item = qscriptvalue_cast<QDomNode*>(thisObject());
  if (item)
    return item->toCharacterData();
  return QDomCharacterData();
}
Example #3
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;
}
bool changeDomElementContents(const QDomElement &element,
                           Predicate p,
                           const QString &newValue,
                           QString *ptrToOldValue = 0)
{
    // Find text in "<element>text</element>"
    const QDomNodeList children = element.childNodes();
    if (children.size() != 1)
        return false;
    const QDomNode first = children.at(0);
    if (first.nodeType() != QDomNode::TextNode)
        return false;
    QDomCharacterData data = first.toCharacterData();
    const QString oldValue = data.data();

    if (p(oldValue)) {
        if (ptrToOldValue)
            *ptrToOldValue = oldValue;
        data.setData(newValue);
        return true;
    }
    return false;
}