[Webkit-unassigned] [Bug 44876] QWebElement::toOuterXml() and QWebElement::toInnerXml() return invalid XML

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Sun Oct 31 10:25:12 PDT 2010


https://bugs.webkit.org/show_bug.cgi?id=44876


Robert Hogan <robert at webkit.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |robert at webkit.org




--- Comment #2 from Robert Hogan <robert at webkit.org>  2010-10-31 10:25:12 PST ---
(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.

-- 
Configure bugmail: https://bugs.webkit.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.



More information about the webkit-unassigned mailing list