Skip to Content.
Sympa Menu

xom-interest - Re: [XOM-interest] Problem parsing HTML file into Document

xom-interest AT

Subject: XOM API for Processing XML with Java

List archive

Chronological Thread  
  • From: Wolfgang Hoschek <wolfgang.hoschek AT>
  • To: "John.Cowan" <jcowan AT>
  • Cc: xom-interest AT
  • Subject: Re: [XOM-interest] Problem parsing HTML file into Document
  • Date: Sun, 11 Dec 2005 21:15:52 -0800

For simplicity, one can simply ignore the tagsoup namespacing via

// find the links of all images in an ill-formed HTML document
XMLReader parser = new org.ccil.cowan.tagsoup.Parser(); // tagsoup parser
parser.setFeature("";, false);
parser.setFeature(" prefixes", false);

Document doc = new Builder(parser).build("";);
Nodes results = XQueryUtil.xquery(doc, "//*:img/@src");

for (int i=0; i < results.size(); i++) {
System.out.println("node "+i+": " + results.get(i).toXML());
//System.out.println("node "+i+": " + XOMUtil.toPrettyXML (results.get(i)));

Note the star in "//*:img/@src"...


On Dec 11, 2005, at 8:59 PM, John.Cowan wrote:

Nick Day scripsit:


Many thanks for the advice!

I am now using TagSoup to parse HTML documents, however I have run into a
problem when attempting to query the resulting Documents using XPath. I
have set up a test method (bottom) which reads in a HTML page from a
specified URL and then queries it using XPath. The matching elements are
then printed out.

This is getting to be a FAQ. TagSoup puts elements into the XHTML namespace,
so you have to use a properly bound prefix to refer to the elements
using XPath.

John Cowan jcowan AT
Big as a house, much bigger than a house, it looked to [Sam], a grey-clad
moving hill. Fear and wonder, maybe, enlarged him in the hobbit's eyes,
but the Mumak of Harad was indeed a beast of vast bulk, and the like of him
does not walk now in Middle-earth; his kin that live still in latter days are
but memories of his girth and his majesty. --"Of Herbs and Stewed Rabbit"
XOM-interest mailing list
XOM-interest AT

Archive powered by MHonArc 2.6.24.

Top of Page