QWebElement::toOuterXml() and QWebElement::toInnerXml() return HTML code that isn't valid XML when they hit certain tags, such as <meta>. This snippet: #include <QApplication> #include <QWebView> #include <QWebFrame> #include <QWebElement> #include <iostream> int main(int argc, char **argv) { QApplication app(argc, argv); QWebView *v=new QWebView(0); v->setHtml("<html><head><meta name=\"author\" content=\"test1\"/></head><body><p>Test</p></body></html>"); std::cerr << qPrintable(v->page()->mainFrame()->documentElement().toOuterXml()) << std::endl; } Prints: <html><head><meta name="author" content="test1"></head><body><p>Test</p></body></html> Note the absence of the closing / (or alternatively, </meta>) in the <meta tag. This is valid HTML, but not valid X(HT)ML -- not what you'd expect from a function named to*Xml.
Chromium 7 has the same behavior using "document.documentElement.outerHTML" from the JS console. The output is: <html><head><meta name="author" content="test1"></head><body><p>Test</p> </body></html> So probably Bernhard is right on the Qt function naming. In fact QWebElement::toOuterXml() returns (HTMLElement*)->outerHTML().
(In reply to comment #0) > QWebElement::toOuterXml() and QWebElement::toInnerXml() return HTML code that isn't valid XML when they hit certain tags, such as <meta>. > > This snippet: > > #include <QApplication> > #include <QWebView> > #include <QWebFrame> > #include <QWebElement> > #include <iostream> > > int main(int argc, char **argv) { > QApplication app(argc, argv); > QWebView *v=new QWebView(0); > v->setHtml("<html><head><meta name=\"author\" content=\"test1\"/></head><body><p>Test</p></body></html>"); > std::cerr << qPrintable(v->page()->mainFrame()->documentElement().toOuterXml()) << std::endl; > } > > > Prints: > <html><head><meta name="author" content="test1"></head><body><p>Test</p></body></html> > > There is a lack of clarity in the documentation, but the behaviour of outerXml() given the method you've used to set the content is sane. To get the result you want you need to do: v->setContent("<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"><head><meta name=\"author\" content=\"test1\"/></head><body><p>Test</p></body></html>", "application/xhtml+xml"); toOuterXml() will then give you the result you expect. Note the warning about setHTML() in the documentation: \warning This function works only for HTML, for other mime types (i.e. XHTML, SVG) setContent() should be used instead. This should probably be given in outerXml() and innerXml() too.
Created attachment 72468 [details] Patch
Comment on attachment 72468 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=72468&action=review r=me, just two things: > WebKit/qt/Api/qwebelement.cpp:319 > + text/xhtml+xml. text/xhtml+xml should be in apostrophes like below. > WebKit/qt/ChangeLog:23 > + Reviewed by NOBODY (OOPS!). Something's up with this ChangeLog entry :)
Created attachment 72866 [details] Patch
Comment on attachment 72866 [details] Patch Clearing flags on attachment: 72866 Committed r71315: <http://trac.webkit.org/changeset/71315>
All reviewed patches have been landed. Closing bug.