Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Qt4 and 'Plain' XPath (1.0) / libxml++
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
Kenji Miyamoto
Veteran
Veteran


Joined: 28 May 2005
Posts: 1452
Location: Looking over your shoulder.

PostPosted: Fri Aug 08, 2008 3:05 pm    Post subject: Qt4 and 'Plain' XPath (1.0) / libxml++ Reply with quote

I've noticed that the new Qt 4.4 has built-in support for XQuery and the like, but I haven't seen any simple examples for its XPath support. Using libxml++, I can just pass an XPath expression to a member function and it'll return a list of nodes, but I can't use it on the moment due to being on a Windows machine and the libxml++ install giving the MSVC R6304 error.

Can Qt4 do the same thing?
_________________
[ Kawa-kun, new and improved!! ]

Alex Libman seems to be more of an anarchist than a libertarian.


Last edited by Kenji Miyamoto on Sat Aug 09, 2008 5:01 am; edited 1 time in total
Back to top
View user's profile Send private message
Kenji Miyamoto
Veteran
Veteran


Joined: 28 May 2005
Posts: 1452
Location: Looking over your shoulder.

PostPosted: Fri Aug 08, 2008 10:46 pm    Post subject: Reply with quote

What I have now is a $document (a Wikipedia page) that prints out everything with the XQuery "doc($document)", but prints nothing with "doc($document)//div[@id='content']".

In XPath 1.0, "//div[@id='content']" prints out what I want.
_________________
[ Kawa-kun, new and improved!! ]

Alex Libman seems to be more of an anarchist than a libertarian.
Back to top
View user's profile Send private message
Kenji Miyamoto
Veteran
Veteran


Joined: 28 May 2005
Posts: 1452
Location: Looking over your shoulder.

PostPosted: Sat Aug 09, 2008 5:05 am    Post subject: Reply with quote

Well, I've turned to libxml++, since it has built-in support for XPath, but I've run into an odd problem:
Code:
void QWikiWindow::set_text(QNetworkReply * fetch) {
   QByteArray data = fetch->readAll();
   QStringList tmp;
   xmlpp::NodeSet::const_iterator i;
   xmlpp::Node * root, * node, * subnode;
   xmlpp::NodeSet nodes;
   xmlpp::Document * subdoc;
   this->ahref.clear();
   try {
      this->parser.parse_memory(Glib::ustring(data.data()));
      if(this->parser) {
         root = this->parser.get_document()->get_root_node();
         // PAGE
         node = root->find("id('content')").front();
         subdoc = new xmlpp::Document;
         subdoc->create_root_node_by_import(node);
         this->page.setPlainText(QString::fromUtf8(subdoc->write_to_string_formatted().data()));
         delete subdoc;
         // LINKS
         nodes = node->find("//p");
         std::cout << "Length: " << nodes.size() << std::endl;
         for(i = nodes.begin(); i != nodes.end(); ++i) {
            std::cout << "PUT" << std::endl;
            subnode = ((xmlpp::Element *)(*i))->get_child_text();
            if(subnode) {
               //std::cout << ((xmlpp::TextNode *)subnode)->get_content().raw() << std::endl;
               tmp << QString::fromUtf8(((xmlpp::TextNode *)subnode)->get_content().data());
            }
         }
         this->linkmodel.setStringList(tmp);
         //nodes = node->find("//a[((parent::p or (parent::li and not(ancestor::table[@class='toc']) and not(ancestor::cite)))) and not(contains(@class, 'external')) and text() and not(contains(@href, 'Special'))]");
      }
      else {
         errp("Parse failed.");
      }
   }
   catch (xmlpp::parse_error e) {
      std::cerr << "Exception caught: " << e.what() << std::endl;
   }
}
This is with a Wikipedia page supplied in data. The id('content') query works just fine, but any // queries for elements (such as //a) return nothing. Strangely, //@ queries for attributes (such as //@title) work just fine.

What's going on?
_________________
[ Kawa-kun, new and improved!! ]

Alex Libman seems to be more of an anarchist than a libertarian.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum