Aye. Is this the kind of dirt you were thinking of?
bool addTag = !e.tagName().isEmpty();
if (addTag) output = "<" + e.tagName();
int len = atts.length();
for (int i = 0; i < len; i++) {
QString name
= atts.
item(i
).
toAttr().
name();
QString value
= atts.
item(i
).
toAttr().
value();
output += " " + name + "=\"" + value + "\"";
}
if (addTag) output += ">";
len = children.length();
for (int i = 0; i < len; i++) {
output += makeTextFromElement(children.item(i).toElement());
}
output += e.text();
if (addTag) output += "</" + e.tagName() + ">";
return output;
}
QString MainWindow::makeTextFromElement(QDomElement e) {
QString tag = e.tagName();
bool addTag = !e.tagName().isEmpty();
QString output = "";
if (addTag) output = "<" + e.tagName();
QDomNamedNodeMap atts = e.attributes();
int len = atts.length();
for (int i = 0; i < len; i++) {
QString name = atts.item(i).toAttr().name();
QString value = atts.item(i).toAttr().value();
output += " " + name + "=\"" + value + "\"";
}
if (addTag) output += ">";
QDomNodeList children = e.childNodes();
len = children.length();
for (int i = 0; i < len; i++) {
output += makeTextFromElement(children.item(i).toElement());
}
output += e.text();
if (addTag) output += "</" + e.tagName() + ">";
return output;
}
To copy to clipboard, switch view to plain text mode
(It's working)
Bookmarks