NancyDotCom wrote:
> Why doesn't this work?
>
> DECLARE @x XML
> SELECT @x = '
> <OnlineResponse xmlns="http://www.myURL.com/schema/online" version="1.0"
> message="Valid Format"></OnlineResponse>'
>
> SELECT @x.query('data(OnlineResponse/@message)') AS message
>
> But if you remove the xmlns attribute from the XML, it works.
OnlineResponse selects elements with local name 'OnlineResponse' in _no
namespace_ while your element is in the namespace
http://www.myURL.com/schema/online. With XQuery you first need to
declare the default namespace with e.g.
SELECT @x.query('declare default element namespace
"http://www.myURL.com/schema/online"; data(OnlineResponse/@message)') AS
message
or you need to use a prefix e.g.
SELECT @x.query('declare namespace
df="http://www.myURL.com/schema/online";
data(df:OnlineResponse/@message)') AS message
A third option is
SELECT @x.query('data(*:OnlineResponse/@message)') AS message
as that selects elements with local name 'OnlineResponse' in any
namespace, including no namespace.
--
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/