[
Lists Home |
Date Index |
Thread Index
]
- To: "Roger L. Costello" <costello@mitre.org>,<xml-dev@lists.xml.org>
- Subject: RE: [xml-dev] Is an XQuery Document an XML Document?
- From: "Dare Obasanjo" <dareo@microsoft.com>
- Date: Sun, 28 Nov 2004 08:39:13 -0800
- Thread-index: AcTVW+ElopXBiRvQSr6mpI9FiV0P2wACc8y3
- Thread-topic: [xml-dev] Is an XQuery Document an XML Document?
I'm not sure what you mean by 'an XQuery document'. However if you mean an XQuery query that generates an XML document, there is no guarantee that it should always be a well-formed XML 1.0 document. After all
<foo />, <bar />
is a valid XQuery expression and it isn't a well formed XML document, then again it doesn't generate a well-formed XML document either.
--
PITHY WORDS OF WISDOM
There is nothing more satisfying that having someone take a shot at you, and miss.
________________________________
From: Roger L. Costello [mailto:costello@mitre.org]
Sent: Sun 11/28/2004 7:06 AM
To: xml-dev@lists.xml.org
Subject: [xml-dev] Is an XQuery Document an XML Document?
Hi Folks,
Here is an example of a fine XQuery document:
<HelloWorld>hello world</HelloWorld>
Is it an XML document?
There is no XML declaration so you might conclude, "No, an XQuery document is
not an XML document."
If that is so then I should be able to omit the end tag with no ill effects:
<HelloWorld>hello world
However, such a document yields an error.
So, you might conclude, "Yes, an XQuery document is an XML document."
Let's dig a little deeper.
A basic constraint in XML is that the "<" symbol is a reserved symbol. If
you wish to use it in your data then you must escape it as such:
<Equation> if (1 < 2) then "TRUE" else "FALSE" </Equation>
For those who have not ventured into XQuery, allow me to explain something
about the workings of XQuery.
If you wish to tell an XQuery Processor that you want it to evaluate an
XPath expression then you wrap the XPath expression within curly braces.
Here's an example:
<Name> {/FitnessCenter/Member[1]/Name} </Name>
The XQuery Processor will evaluate the XPath expression within the curly
braces. The result will be:
<Name>Jeff</Name>
(Jeff is the name of the first member)
In XPath 2.0 there is an if-then-else expression. So, here is an example
of an XQuery document which uses an XPath if-then-else expression:
<Equation> {if (1 < 2) then "TRUE" else "FALSE"} </Equation>
The result of an XQuery Processor executing this will be:
<Equation>TRUE</Equation>
Do you notice something odd about this example? It uses the "<" symbol
without escaping it! In fact, if you were to escape the "<" symbol ...
<Equation> {if (1 < 2) then "TRUE" else "FALSE"} </Equation>
... it would result in an error being generated!
So, you might conclude, "A fundamental rule in XML is that the "<" symbol
is reserved and must be escaped. XQuery does not heed this rule.
Therefore, an XQuery document is not an XML document."
Okay, I give up. Which is it? XML or not? If it's not XML then why
is it called "XML Query Language"? /Roger
|