Reputation: 42613
Qt 4.7 DOM API seems kind of strange :(. I have a text HTML representation and need to get "title" text. Seems very easy, but following code is not working, i get empty string:
QDomDocument dom;
dom.setContent( "<html><head><title>this is a title</title></head></html>" );
QString title = dom.elementsByTagName( "title" ).item( 0 ).nodeValue();
Any suggestions?
Upvotes: 1
Views: 147
Reputation: 1119
Try this:
QString title = dom.elementsByTagName( "title" ).item( 0 ).firstChild().nodeValue();
Because the tree structure for text is:
node <title>
=> text element
Upvotes: 2