xom-interest AT lists.ibiblio.org
Subject: XOM API for Processing XML with Java
List archive
- From: Christophe Marchand <christophe.marchand AT axyus.com>
- To: XOM API for Processing XML with Java <xom-interest AT lists.ibiblio.org>
- Subject: Re: [XOM-interest] using xpath and querying html
- Date: Thu, 29 Oct 2009 08:01:15 +0100
As you define "html" as the prefix, your request should be
/html:html/html:body/html:table/html:tbody/html:tr/html:td/html:table/html:tbody/html:tr/html:td/html:table[2]/html:tbody/html:tr/html:td[2]/html:table/html:tbody/html:tr/html:td/html:table[4]/html:tbody/html:tr[3]/html:td[3]
You can also add a mapping beween the default prefix "" and "http://www.w3.org/1999/xhtml" to your XPathContext
Christophe
Jason Novotny a écrit :
Hi,
I'm completely new to xpath but after finding an interesting post on using XOM, Saxon and TagSoup I have a simple example below:
XMLReader tagsoup = XMLReaderFactory.createXMLReader("org.ccil.cowan.tagsoup.Parser");
tagsoup.setFeature("http://xml.org/sax/features/namespace-prefixes",true);
Builder builder = new Builder(tagsoup);
String url = "http://myurl.com";
Document doc = builder.build(url);
XPathContext context = new XPathContext("html", "http://www.w3.org/1999/xhtml");
// THIS ONE WORKS
Nodes estimated = doc.query("//html:span[@class='small_title'][2]", context);
for (int i = 0; i < estimated.size(); i++) {
System.err.println(estimated.get(i).toXML());
}
// THIS DOESN'T
Nodes results = doc.query("//html/body/table/tbody/tr/td/table/tbody/tr/td/table[2]/tbody/tr/td[2]/table/tbody/tr/td/table[4]/tbody/tr[3]/td[3]", context);
for (int i = 0; i < results.size(); i++) {
System.err.println(results.get(i).toXML());
}
So my problem is the syntax-- the first query works fine but the second one doesn't-- I actually pulled this query string from using Firebug and doing "copy XPath"...
Any guidance on libraries I can use or the proper syntax with dealing with HTML querying would be greatly appreciated!
Thanks, Jason
_______________________________________________
XOM-interest mailing list
XOM-interest AT lists.ibiblio.org
http://lists.ibiblio.org/mailman/listinfo/xom-interest
-
[XOM-interest] using xpath and querying html,
Jason Novotny, 10/28/2009
-
Re: [XOM-interest] using xpath and querying html,
Christophe Marchand, 10/29/2009
- Re: [XOM-interest] using xpath and querying html, Jason Novotny, 10/29/2009
-
Re: [XOM-interest] using xpath and querying html,
Christophe Marchand, 10/29/2009
Archive powered by MHonArc 2.6.24.