0

We abuse the QWebFrame as a html parser

QString html = "<img src=\"input_213123dfh\" />";
QWebFrame* frame = htmlProcessor.mainFrame();
frame->setHtml(html);
QWebElementCollection inputs = frame->documentElement().findAll("img[src*=input_]");
foreach (QWebElement input, inputs) {
    input.setOuterXml(QString("<input type=\"text\" uuid=\"%1\" />").arg(input.attribute("src").section("_",1,1)));
}
html = frame->toHtml();

which outputs

<html><head></head><body><input type="text" uuid="213123dfh"></body></html>

our Problem is that the input tag in the output is not self-closing. Is it possible to get html with self-closed tags?

wutzebaer
  • 14,365
  • 19
  • 99
  • 170

1 Answers1

0

This is a dead-end. It won't be portable to QWebEngine and as you can see it doesn't quite work.

Instead, you should iterate the DOM from javascript, and you can emit the xhtml there.

Kuba hasn't forgotten Monica
  • 95,931
  • 16
  • 151
  • 313