本文整理汇总了C++中QDomElement::removeAttributeNode方法的典型用法代码示例。如果您正苦于以下问题:C++ QDomElement::removeAttributeNode方法的具体用法?C++ QDomElement::removeAttributeNode怎么用?C++ QDomElement::removeAttributeNode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QDomElement
的用法示例。
在下文中一共展示了QDomElement::removeAttributeNode方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: cleanMathml
void cleanMathml(QDomElement pElement)
{
// Clean up the current element
// Note: the idea is to remove all the attributes that are not in the
// MathML namespace. Indeed, if we were to leave them in then the XSL
// transformation would either do nothing or, worst, crash OpenCOR...
static const QString MathmlNamespace = "http://www.w3.org/1998/Math/MathML";
QDomNamedNodeMap attributes = pElement.attributes();
QList<QDomNode> nonMathmlAttributes = QList<QDomNode>();
for (int i = 0, iMax = attributes.count(); i < iMax; ++i) {
QDomNode attribute = attributes.item(i);
if (attribute.namespaceURI().compare(MathmlNamespace))
nonMathmlAttributes << attribute;
}
foreach (QDomNode nonMathmlAttribute, nonMathmlAttributes)
pElement.removeAttributeNode(nonMathmlAttribute.toAttr());
// Go through the element's child elements, if any, and clean them up
for (QDomElement childElement = pElement.firstChildElement();
!childElement.isNull(); childElement = childElement.nextSiblingElement()) {
cleanMathml(childElement);
}
}
示例2: clearAttributes
void DomConvenience::clearAttributes(QDomElement& e)
{
QDomNamedNodeMap attrMap = e.attributes();
QDomNode attrNode;
for (uint i = attrMap.length(); i > 0; --i)
e.removeAttributeNode(attrMap.item(i - 1).toAttr());
}
示例3: sipConvertFromNewType
static PyObject *meth_QDomElement_removeAttributeNode(PyObject *sipSelf, PyObject *sipArgs)
{
PyObject *sipParseErr = NULL;
{
const QDomAttr* a0;
QDomElement *sipCpp;
if (sipParseArgs(&sipParseErr, sipArgs, "BJ9", &sipSelf, sipType_QDomElement, &sipCpp, sipType_QDomAttr, &a0))
{
QDomAttr*sipRes;
sipRes = new QDomAttr(sipCpp->removeAttributeNode(*a0));
return sipConvertFromNewType(sipRes,sipType_QDomAttr,NULL);
}
}
/* Raise an exception if the arguments couldn't be parsed. */
sipNoMethod(sipParseErr, sipName_QDomElement, sipName_removeAttributeNode, doc_QDomElement_removeAttributeNode);
return NULL;
}
示例4: 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);
}
}