qt XML中的HTML节点,转换为html格式的字符串

来源:互联网 发布:tensorflow cuda9.0 编辑:程序博客网 时间:2024/03/29 13:44
<p>// Xml 中的 HTML 解析,拼接为字符串</p>
void elemToString(QDomElement htmlElem, QString &htmlText){    // 属性.行    htmlText.append("<").append(htmlElem.tagName());    QDomNamedNodeMap map = htmlElem.attributes();    for(int i= 0; i <map.count(); i++)    {        QDomAttr attr = map.item(i).toAttr();        htmlText.append(QString(" %1=%2").arg(attr.name(),attr.value()));    }    htmlText.append(">");    // 子节点    QDomNodeList nodeList = htmlElem.childNodes();    int count = nodeList.count();    if(count)    {        for(int j= 0; j <count; j++)        {            QDomElement tempElem = nodeList.at(j).toElement();            if(tempElem.tagName().isEmpty())                htmlText.append(htmlElem.text());            else                /// --- ---  递归  --- ---                elemToString(tempElem, htmlText);        }    }    // 结束.行    htmlText.append(QString("</%1>").arg(htmlElem.tagName()));}


后来又发现了一个类,,,,,


    // 读
    QDomElement elem = ...;
    QDomComment comment = elem.firstChild().toComment();
    comment.nodeValue();
// 写
    comment = elem.createComment("2ble");
    elem.appendChild(cmt);
    comment.setNodeValue("TestTestTest");

                                             
0 0