Parsing XML with nodes containing HTML in Qt -


i try parse xml file nodes containing html in qt, looks this:

<root>  <list>   <element>some <i>text<i></element>   <element><b>another line of text<b></element>   <element><i>tag opened here</element>   <element>and closed here</i></element>  </list> </root> 

i tried different approaches in qt, getting html node somehow not possible (in easy way).

qdomdocument:
way found text of qdomelement: use save() function (documentation), whole line "<element>...</element>", not inner text.

qxmlstreamreader
there function readelementtext(qxmlstreamreader::includechildelements) (documentation), removes html tags, text of first example "some text".

can done in more effective way?

i thought of solution, think it:

how wrapping contents of <element> tags in cdata sections (using string replace or regex functions) before xml file parsed?

neither qdomdocument nor qxmlstreamreader able parse html. xml parsers. parse html in qt should use qtwebkit.

#include <qtcore> #include <qtgui> #include <qtwebkit>  int main(int argc, char ** argv) {     qapplication app(argc, argv);      qstring html =     "                                                   \\     <root>                                              \\      <list>                                             \\       <element>some <i>text<i></element>                \\       <element><b>another line of text<b></element>     \\       <element><i>tag opened here</element>             \\       <element>and closed here</i></element>            \\      </list>                                            \\     </root>                                             \\     ";      qwebpage page;     page.mainframe()->sethtml(html);     qwebelement htmlelement = page.mainframe()->findfirstelement("root list element i");     qdebug() << htmlelement.toplaintext();      return app.exec(); } 

output:

"text" 

Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -