|
[XQuery Talk Mailing List Archive Home] [By Date] [By Thread] [By Subject] [By Author] [Recent Entries] [Reply To This Message] XHTML with embedded XQuery: how to deal with the DOCTYPE declaration? How to deal with the default XHTML namespaces?Costello, Roger L. costello at mitre.orgSat Mar 27 10:43:12 PST 2010
Hi Folks,
I am creating an XHTML document and embedding XQuery in it:
---------------------------------------------------------
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
...
</head>
<body>
<h1>Our Solar System Planets</h1>
<div id="planets">
{
for $i in //planet return
...
}
</div>
</body>
</html>
---------------------------------------------------------
Here is my XML document:
<?xml version="1.0" encoding="UTF-8"?>
<planets>
<planet>
...
</planet>
...
</planets>
Note that my XML document doesn't use namespaces.
QUESTION #1
When I execute the XHTML document (containing XQuery) I get an error message regarding the DOCTYPE declaration:
Error on line 1 column 0 of planets.xq:
XPST0003: XQuery syntax error in #<!D#:
Expected '--' or '[CDATA[' after '<!'
Static error(s) in query
Do I need to do something special for DOCTYPE declarations?
QUESTION #2
After stripping out the DOCTYPE declaration, and then executing it, I still don't get the desired results. I discovered the reason: I have a default namespace declaration (the XHTML namespace):
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
My XQuery is trying to reference the planet elements in the XHTML namespace:
for $i in //planet return
Here are two approaches to fix this problem:
(a) Explicitly qualify all the XHTML elements:
<xhtml:html xmlns:xhtml="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<xhtml:head>
...
</xhtml:head>
<xhtml:body>
...
</xhtml:html>
(b) Declare a null namespace, and then explicitly qualify the references to the planet elements:
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"
xmlns:p="">
<head>
...
</head>
<body>
for $i in //p:planet return
</html>
Neither approach is very attractive. Is there a better approach?
/Roger
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|






