[XOM-interest] unable to get xquery to work

William Chu willchu at gmail.com
Fri Apr 4 03:42:27 EDT 2008


Hello,

I am trying to apply a simple xquery to a very basic page.

The query is this: /html

The page is: <html>hi</html>

When doing so with the following code, I get no results back -
results.size is equal to 0.

Why is this happening? I am expecting that I should get "hi" back.

Thanks for the help!
Will

public class Soup {

    public static void main (String argv[]) {
	try {
	
	    String page = "<html>hi</html>";
	    ByteArrayInputStream in = new ByteArrayInputStream(page.getBytes());
	    String xqueryScript = "/html";
            XMLReader parser = new org.ccil.cowan.tagsoup.Parser(); //
tagsoup parser
            Document doc = new Builder(parser).build(in);
            System.out.println (doc.toXML());
            Nodes results = XQueryUtil.xquery(doc, xqueryScript);
            if (results.size() < 1) {
                System.out.println ("size is less than 1");
            	
            }
            System.out.println (results.get(0).toXML());
        }
	catch (Exception e) {
	    e.printStackTrace();
	}
    }
}


More information about the XOM-interest mailing list