本文整理汇总了C++中QDomAttr::prefix方法的典型用法代码示例。如果您正苦于以下问题:C++ QDomAttr::prefix方法的具体用法?C++ QDomAttr::prefix怎么用?C++ QDomAttr::prefix使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QDomAttr
的用法示例。
在下文中一共展示了QDomAttr::prefix方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: cleanDomElement
void cleanDomElement(QDomElement &pDomElement,
QMap<QString, QString> &pElementsAttributes)
{
// Serialise all the element's attributes and sort their serialised version
// before removing them from the element and adding a new attribute that
// will later on be used for string replacement
static qulonglong attributeNumber = 0;
static const int ULLONG_WIDTH = ceil(log(ULLONG_MAX));
if (pDomElement.hasAttributes()) {
QStringList serialisedAttributes = QStringList();
QDomNamedNodeMap domElementAttributes = pDomElement.attributes();
QDomAttr attributeNode;
while (domElementAttributes.count()) {
// Serialise (ourselves) the element's attribute
// Note: to rely on QDomNode::save() to do the serialisation isn't
// good enough. Indeed, if it is going to be fine for an
// attribute that doesn't have a prefix, e.g.
// name="my_name"
// it may not be fine for an attribute with a prefix, e.g.
// cmeta:id="my_cmeta_id"
// since depending on how that attribute has been created
// (i.e. using QDomDocument::createAttribute() or
// QDomDocument::createAttributeNS()), then it may or not have
// a namespace associated with it. If it does, then its
// serialisation will look something like
// cmeta:id="my_cmeta_id" xmlns:cmeta="http://www.cellml.org/metadata/1.0#"
// which is clearly not what we want since that's effectively
// two attributes in one. So, we need to separate them, which
// is what we do here, after making sure that the namespace
// for the attribute is not already defined for the given DOM
// element...
attributeNode = domElementAttributes.item(0).toAttr();
if (attributeNode.namespaceURI().isEmpty()) {
serialisedAttributes << attributeNode.name()+"=\""+attributeNode.value()+"\"";
} else {
serialisedAttributes << attributeNode.prefix()+":"+attributeNode.name()+"=\""+attributeNode.value()+"\"";
if ( attributeNode.prefix().compare(pDomElement.prefix())
&& attributeNode.namespaceURI().compare(pDomElement.namespaceURI())) {
serialisedAttributes << "xmlns:"+attributeNode.prefix()+"=\""+attributeNode.namespaceURI()+"\"";
}
}
// Remove the attribute node from the element
pDomElement.removeAttributeNode(attributeNode);
}
// Sort the serialised attributes, using the attributes' name, and
// remove duplicates, if any
std::sort(serialisedAttributes.begin(), serialisedAttributes.end(), sortSerialisedAttributes);
serialisedAttributes.removeDuplicates();
// Keep track of the serialisation of the element's attribute
QString elementAttributes = QString("Element%1Attributes").arg(++attributeNumber, ULLONG_WIDTH, 10, QChar('0'));
pElementsAttributes.insert(elementAttributes, serialisedAttributes.join(" "));
// Add a new attribute to the element
// Note: this attribute, once serialised by QDomDocument::save(), will
// be used to do a string replacement (see
// qDomDocumentToString())...
domElementAttributes.setNamedItem(pDomElement.ownerDocument().createAttribute(elementAttributes));
}
// Recursively clean ourselves
for (QDomElement childElement = pDomElement.firstChildElement();
!childElement.isNull(); childElement = childElement.nextSiblingElement()) {
cleanDomElement(childElement, pElementsAttributes);
}
}