本文整理汇总了C++中QDomElement::setAttributeNodeNS方法的典型用法代码示例。如果您正苦于以下问题:C++ QDomElement::setAttributeNodeNS方法的具体用法?C++ QDomElement::setAttributeNodeNS怎么用?C++ QDomElement::setAttributeNodeNS使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QDomElement
的用法示例。
在下文中一共展示了QDomElement::setAttributeNodeNS方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: addCorrectNS
QDomElement addCorrectNS(const QDomElement &e)
{
int x;
// grab child nodes
/*QDomDocumentFragment frag = e.ownerDocument().createDocumentFragment();
QDomNodeList nl = e.childNodes();
for(x = 0; x < nl.count(); ++x)
frag.appendChild(nl.item(x).cloneNode());*/
// find closest xmlns
QDomNode n = e;
while(!n.isNull() && !n.toElement().hasAttribute("xmlns") && n.toElement().namespaceURI() == "" )
n = n.parentNode();
QString ns;
if(n.isNull() || !n.toElement().hasAttribute("xmlns")){
if (n.toElement().namespaceURI () == ""){
ns = "jabber:client";
} else {
ns = n.toElement().namespaceURI();
}
} else {
ns = n.toElement().attribute("xmlns");
}
// make a new node
QDomElement i = e.ownerDocument().createElementNS(ns, e.tagName());
// copy attributes
QDomNamedNodeMap al = e.attributes();
for(x = 0; x < al.count(); ++x) {
QDomAttr a = al.item(x).toAttr();
if(a.name() != "xmlns")
i.setAttributeNodeNS(a.cloneNode().toAttr());
}
// copy children
QDomNodeList nl = e.childNodes();
for(x = 0; x < nl.count(); ++x) {
QDomNode n = nl.item(x);
if(n.isElement())
i.appendChild(addCorrectNS(n.toElement()));
else
i.appendChild(n.cloneNode());
}
//i.appendChild(frag);
return i;
}
示例2: stripExtraNS
// stripExtraNS
//
// This function removes namespace information from various nodes for
// display purposes only (the element is pretty much useless for processing
// after this). We do this because QXml is a bit overzealous about outputting
// redundant namespaces.
static QDomElement stripExtraNS(const QDomElement &e)
{
// find closest parent with a namespace
QDomNode par = e.parentNode();
while(!par.isNull() && par.namespaceURI().isNull())
par = par.parentNode();
bool noShowNS = false;
if(!par.isNull() && par.namespaceURI() == e.namespaceURI())
noShowNS = true;
// build qName (prefix:localName)
QString qName;
if(!e.prefix().isEmpty())
qName = e.prefix() + ':' + e.localName();
else
qName = e.tagName();
QDomElement i;
int x;
if(noShowNS)
i = e.ownerDocument().createElement(qName);
else
i = e.ownerDocument().createElementNS(e.namespaceURI(), qName);
// copy attributes
QDomNamedNodeMap al = e.attributes();
for(x = 0; x < al.count(); ++x) {
QDomAttr a = al.item(x).cloneNode().toAttr();
// don't show xml namespace
if(a.namespaceURI() == NS_XML)
i.setAttribute(QString("xml:") + a.name(), a.value());
else
i.setAttributeNodeNS(a);
}
// copy children
QDomNodeList nl = e.childNodes();
for(x = 0; x < nl.count(); ++x) {
QDomNode n = nl.item(x);
if(n.isElement())
i.appendChild(stripExtraNS(n.toElement()));
else
i.appendChild(n.cloneNode());
}
return i;
}
示例3: sipConvertFromNewType
static PyObject *meth_QDomElement_setAttributeNodeNS(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->setAttributeNodeNS(*a0));
return sipConvertFromNewType(sipRes,sipType_QDomAttr,NULL);
}
}
/* Raise an exception if the arguments couldn't be parsed. */
sipNoMethod(sipParseErr, sipName_QDomElement, sipName_setAttributeNodeNS, doc_QDomElement_setAttributeNodeNS);
return NULL;
}