From: <cra...@co...> - 2009-04-02 02:18:22
|
I don't think vtd-xml is intended for html unless it is xhtml... if it is an XML file.. could you provide an example of the data, just to remove ambiguity? ----- Original Message ----- From: "Vincent Chan" <vi...@gm...> To: vtd...@li... Sent: Wednesday, April 1, 2009 12:53:40 AM GMT -08:00 US/Canada Pacific Subject: [Vtd-xml-users] How to traverse to nodes from current node after evalXPath? Hi, I am using vtd-xml to parse html. The structure of html is unknown until run-time. After I used xpath to locate the <p> that I want, I want to find <img>s that matches certain src are inside the <p>, before the <p> or after <p>. How? Thanks. VTDNav vn = vg.getNav(); AutoPilot ap = new AutoPilot (vn); try { ap.selectXPath ("//p[matches(.,'[\\p{Space}\\p{Punct}]" + term + "[\\p{Space}\\p{Punct}]'"); } catch (com.ximpleware.XPathParseException e) { } try { while ((j = ap.evalXPath ()) != -1) { // loop through all matching <p> try { if (vn.toString (j).split (" ").length >= MIN_NUM_WORDS_IN_SNIPPET) {// if word count in this paragraph is larger than the minimum, I found the paragraph. Otherwise, continue to loop sbSnippet.append (vn.toString (j)); break; } } catch (com.ximpleware.NavException e) { } } } catch (com.ximpleware.XPathEvalException e) { } catch (com.ximpleware.NavException e) { } // find whether <img>s with matched src are inside <p>, before <p> or after <p> // How? ap.resetXPath (); ------------------------------------------------------------------------------ _______________________________________________ Vtd-xml-users mailing list Vtd...@li... https://lists.sourceforge.net/lists/listinfo/vtd-xml-users |