Page 1 of 1

Extracting data from an XHTML file with XQuery

Posted: Thu Sep 18, 2008 2:41 pm
by sampablokuper
Hi all,

I have an XHTML document as follows:

Code: Select all

<!DOCTYPE html SYSTEM "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Foo</title>
</head>
<body>Bar</body>
</html>
which I call index.html .

I also have the following XQuery files:

Code: Select all

for $markup in /*
return $markup
which I call test_one.xquery, and:

Code: Select all

for $markup in /html/*
return $markup
which I call test_two.xquery .

When I use the XQuery debugging view in Oxygen, and select index.html as my XML file, test_one.xquery as my XQuery file and Saxon-B as my XQuery engine in the Control Toolbar, running the XQuery gives the following output:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Foo</title>
</head>
<body>Bar</body>
</html>
But when I do the same thing with test_two.xquery selected instead, I get the following output:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
Why is it that test_two.xquery gives no output (aside from the XML header line)?

Thanks in advance for your help!

Sam

Re: Extracting data from an XHTML file with XQuery

Posted: Thu Sep 18, 2008 3:02 pm
by sorin_ristache
Hello,

You get an empty result with test_two.xquery because you did not specify the correct namespace for the html element. You should use a namespace declaration:

Code: Select all

declare namespace xhtml="http://www.w3.org/1999/xhtml";

for $markup in /xhtml:html/*
return $markup
In test_one.xquery the * matches elements from any namespace.


Regards,
Sorin

Re: Extracting data from an XHTML file with XQuery

Posted: Thu Sep 18, 2008 3:39 pm
by sampablokuper
Hi Sorin,

Thanks for your help! That's fixed it for me :D

Sam