View previous topic :: View next topic |
Author |
Message |
Kenji Miyamoto Veteran
Joined: 28 May 2005 Posts: 1452 Location: Looking over your shoulder.
|
Posted: Fri Aug 08, 2008 3:05 pm Post subject: Qt4 and 'Plain' XPath (1.0) / libxml++ |
|
|
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 |
|
|
Kenji Miyamoto Veteran
Joined: 28 May 2005 Posts: 1452 Location: Looking over your shoulder.
|
Posted: Fri Aug 08, 2008 10:46 pm Post subject: |
|
|
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 |
|
|
Kenji Miyamoto Veteran
Joined: 28 May 2005 Posts: 1452 Location: Looking over your shoulder.
|
Posted: Sat Aug 09, 2008 5:05 am Post subject: |
|
|
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 |
|
|
|
|
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
|
|