c++ - How to parse xml with qt? -
i'm trying parse html page qt using qtxmlquery, with:
query.setfocus(qnetworkreply->readall());
but receive following error message:
error fodc0002 in tag:trolltech.com,2007:qtxmlpatterns:qiodevicevariable:u, @ line 3, column 44: entity 'ndash' not declared.
i think means html page i'm trying read malformed. how fix page ?
first maybe check if ndash declared in xml:
<!entity ndash "–"> <!-- en dash, u+2013 isopub --> <!entity mdash "—"> <!-- em dash, u+2014 isopub -->
named entities, known internal entities in xml specifications, refer when talk "entities." declare them in either dtd or internal subset (that is, part of statement in document) , use them in document references. during xml document parsing, entity reference replaced representation. in plain english, these entities macros expanded when process document.
example:
<!doctype article public "-//nlm//dtd journal publishing dtd v3.0 20080202//en" "journalpublishing3.dtd" [<!entity ndash "–">]
if ok alternatively try else: can use builtin qtwebkit. example:
class mypageloader : public qobject { q_object public: mypageloader(); void loadpage(const qurl&); public slots: void replyfinished(bool); private: qwebview* m_view; }; mypageloader::mypageloader() { m_view = new qwebview(); connect(m_view, signal(loadfinished(bool)), this, slot(replyfinished(bool))); } void mypageloader::loadpage(const qurl& url) { m_view->load(url); } void mypageloader::replyfinished(bool ok) { qwebelementcollection elements = m_view->page()->mainframe()->findallelements("a"); foreach (qwebelement e, elements) { // process element e } }
to use class
mypageloader loader; loader.loadpage("http://www.google.com")
you can find wraper here
to retrieve element:
qwebview* view = new qwebview(parent); view.load(qurl("http://www.your_site.com")); qwebelementcollection elements = view.page().mainframe().findallelements("a");
Comments
Post a Comment