[webkit-dev] Problems with using XPath functionality to query DOM

Steve Hanna sch at eecs.berkeley.edu
Wed Feb 17 18:27:54 PST 2010


Hi all, I'm trying to use WebKit's interface to discover nodes that I
may be interested in exploring or working with. However, the below
code never returns a node list. However, document is valid, and I can
print the contents of the HTML. The only item on the webpage I have
been testing is a submit button. Previous attempts include \\*, and
other queries. Nothing seems to work. I've been debugging and stepping
through webkit all day. The strangest error I have found is (in
XPathResult), while stepping through the iterateNext, somehow the
result type because 111 -- which causes this to exit. I have spent a
ton of time looking for the cause of this, but I seem to be doing
everything properly. If anyone can provide advice on this, it would be
greatly appreciated.

Thanks!


181 Node* XPathResult::iterateNext(ExceptionCode& ec)
182 {
183     /*
184     if (resultType() != UNORDERED_NODE_ITERATOR_TYPE &&
resultType() != ORDERED_NODE_ITERATOR_TYPE) {
185         ec = XPathException::TYPE_ERR;
186         return 0;
187     }*/


128 void FlaxSymbolTracker::processPreExperimentHandlers() {
129     WebCore::Document* doc = getDocument();
130     if (doc == NULL) {
131         flax_msg(VERBOSE, DETAILS, "Could not process pre
experiment handlers! Document object was NULL!");
132         return;
133     }
134     WebCore::ExceptionCode ec;
135     WebCore::String query("//input");
136     WebCore::XPathResult* xpr = doc->evaluate(query,
dynamic_cast<WebCore::Node*>(doc), NULL,
WebCore::XPathResult::UNORDERED_NODE_ITERATOR_TYPE, NULL, ec).get();
137     if (xpr == 0 ) {
138         flax_msg(VERBOSE, DETAILS, "Could not find query(\"%s\")
in DOM", wkstring_to_string(query).c_str());
139         return;
140     }
141     flax_msg(VERBOSE, DETAILS, "Document is: %s ",
wkstring_to_string(doc->body()->innerHTML()).c_str());
142     flax_msg(VERBOSE, DETAILS, "Document is%s a valid context
node.", WebCore::XPath::isValidContextNode(dynamic_cast<WebCore::Node*>(doc))
? "" : " not");
143
144     WebCore::Node* cur_node = xpr->iterateNext(ec);
145     flax_msg(VERBOSE,DETAILS, "XPath Query Result\n");
146     if(!cur_node)
147         return;
148
149
150     do{
151         flax_msg(VERBOSE, DETAILS, "%s",
wkstring_to_string((WebCore::XPath::stringValue(cur_node))).c_str());
152     }while(0 != (cur_node = xpr->iterateNext(ec)));
153     m_pehLoaded = true;


-- 
Steve Hanna
Life size models of Cthulhu, on sale now!
http://www.vividmachines.com/


More information about the webkit-dev mailing list