Skip to Content.
Sympa Menu

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

xom-interest AT lists.ibiblio.org

Subject: XOM API for Processing XML with Java

List archive

Chronological Thread  
  • From: Wolfgang Hoschek <wolfgang.hoschek AT mac.com>
  • To: "John.Cowan" <jcowan AT reutershealth.com>
  • Cc: xom-interest AT lists.ibiblio.org
  • 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("http://xml.org/sax/features/namespaces";, false);
parser.setFeature("http://xml.org/sax/features/namespace- prefixes", false);

Document doc = new Builder(parser).build("http://www.yahoo.com";);
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"...

Wolfgang.

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

Nick Day scripsit:

Hi,

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 reutershealth.com www.reutershealth.com www.ccil.org/~cowan
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 lists.ibiblio.org
http://lists.ibiblio.org/mailman/listinfo/xom-interest






Archive powered by MHonArc 2.6.24.

Top of Page