Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: SQL Server 2005 XML: Namespaces Not Being Hit/Used

11 views
Skip to first unread message

Michael Rys [MSFT]

unread,
Sep 20, 2005, 8:30:58 PM9/20/05
to
You are missing:

a) That the fn prefix is predefined in the methods to the July 2004 working
draft. If you overwrite it with a later namespace, it will be taken as a
function that we have no knowledge about.
b) That we currently do not implement all functions of the XQuery F&O
library (for a variety of reasons, including stability of the spec). Books
Online provides you with the list of functions that we implement.

I hope this helps.
Michael

"GrasshopperQ" <Grassh...@discussions.microsoft.com> wrote in message
news:048B4EFF-93DF-46F2...@microsoft.com...
> Any use of namespaces within SQL Server 2005 XQueries or Schemas has been
> completely fruitless for me. E.g.
>
> SELECT
> @ValidXML.value('declare namespace
> fn="http://www.w3.org/2005/04/xpath-functions";
> fn:month-from-date(shiftDate)', 'varchar(2)')
>
> consistently produces the following error:
>
> Msg 2395, Level 16, State 1, Procedure HgTimeClock_LoadEntries, Line 40
> XQuery [value()]: There is no function
> '{http://www.w3.org/2005/04/xpath-functions}:month-from-date()'
>
> This is not the only example of a namespace not being used, though I won't
> bore you with the rest.
>
> Can someone PLEASE tell me what I'm missing?
>
> Thanks!


GrasshopperQ

unread,
Sep 21, 2005, 12:36:04 PM9/21/05
to
That helps solve 1/2 my problem, and many thanks for that. I now know that I
can use only the very few functions available not in the xpath-functions
namespace, but in...wherever SQL Server stores the functions that are gotten
from http://www.w3.org/2004/07/xpath-functions.

There's still the question of it it means anything at all to put references
to outside (non-SQL Server) namespaces in any XML? E.g. writing an XQuery
such as

'declare namespace func="http://www.w3.org/2005/02/xpath-functions";
hours-from-datetime("2005-01-01T08:00:00Z")'

would be worthless since it really doesn't go out to that namespace to get
those standard XPath Functions.

Is that correct?

Michael Rys [MSFT]

unread,
Sep 21, 2005, 12:55:44 PM9/21/05
to
Note that in XQuery, the namespace declaration is just associating a prefix
with a URI. It does not load any resources. If you look at the XQuery
processing model in the XQuery spec, you will see that there is a set of
preloaded functions that the names can be resolved to. At some point, we may
add more functions to that list, including different namespace versions of
the same function.

Best regards
Michael


"GrasshopperQ" <Grassh...@discussions.microsoft.com> wrote in message

news:AEA1FFB8-72A6-477E...@microsoft.com...

GrasshopperQ

unread,
Sep 21, 2005, 1:14:04 PM9/21/05
to
Is there a reason at all, then, to use namespace references in any
XML-related functionality in SQL Server? If I reference an XLST or an online
custom set of xpath functions or whatever, and it's not going out there to
get the reference, it would make sense to not bother with namespaces, right?

Michael Rys [MSFT]

unread,
Sep 21, 2005, 4:42:32 PM9/21/05
to
Namespaces serve a specific base semantics: To allow to scope names to an
application-specific domain to avoid name clashes. Declaring the prefixes in
XQuery and XML is a purely syntactic way of having to avoid to write
/{http://www.example.com}doc/{....}element etc every time.

In addition, the URIs can be associated with resources such as a schema
collection, a document, or a function library. However, you need mechanisms
to manage such resources inside the database for a variety of reasons
(stability of metadata and data, security etc).

In SQL Server 2005, we currently only provide schema collections and since
we have external mechanisms to bind them to the data, the XQuery
functionality can pick them up. However, even though we now have schema
namespace URIs implicitly made available, we still need a way to bind the
prefixes to be able to refer to the types, elements and attributes defined
in the schema. That's why you still need the namespace declaration syntax.

For example, if you define a schema collection SC that contains a schema
with the target namespace http://example.com and a user-defined atomic type
hatSize that derives from xs:integer, you want to be able to write XQueries
such as

declare namespace f = "http://example.com";
f:hatSize(6) (:casts 6 to an instance of hatSize :)

declare namespace f= "http://example.com";
data(/f:doc/f:a/@f:x) instance of f:hatSize

Best regards
Michael

"GrasshopperQ" <Grassh...@discussions.microsoft.com> wrote in message

news:AFF87091-3187-4648...@microsoft.com...

0 new messages