Re: SQL2005, validation, & XQuery
- From: "Han" <hp4444@xxxxxxxxxxxxxxxx>
- Date: Fri, 22 Dec 2006 20:22:54 +0900
Mark
I think you are experiencing occurence issue, not namespace.
xcol.value('xpath', 'type')
is error.
Instead, you should make the xpath part singleton. For example,
xcol.value('(xpath)[1]', 'type')
Note,
()[1]
One of the common misunderstanding is confusing between
xpath[1] and (xpath)[1]
The first just means there is no preceding-sibling before the context node,
while the second means only one first node in the entire document.
Except the occurence part, your xpath syntax is correct. Such as,
xcol.value('(/*[local-name()="name"])[1], 'type')
"Mark" <mmodrall@xxxxxxxxxxxxx> wrote in message
news:6CECEA6E-0086-47B3-9D29-3540599E486D@xxxxxxxxxxxxxxxx
My thanks to both Han and Wei for your help; I was able to get it to work.
And Han's multiple approaches are also very helpful.
Coming more from an xpath background, one that I tried that *didn't* work
was
xml_col.value('/*[local-name() = "test"]', 'varchar(50)');
I got an error saying that the wildcard made the result indeterminate,
even
though the qualifier (I thought) should have addressed that. I also tried
xml_col.value('/*[local-name() = "test" and position()=1]',
'varchar(50)');
and with position() as the first qualifier, but I kept getting the error
that the wildcard made the result indeterminate.
This didn't seem to be based on the xml in the column at all - only on a
very limited reading of the query (not taking the qualifiers into
account).
The xml in my sample columns only *had* one node:
<test xmlns="http://ex.org/test">this</test>
and
<t1:test xmlns:t1="http://ex.org/test">this</t1:test>
The first was the only row in my test db to start, but when I had trouble
with the query I thought it might be related to the default namespace so I
added another row with the 2nd xml. It didn't work; I still got the same
complaint about the local-name() formulation. I hadn't thought of
"/*:test".
Still, rejecting the local-name() qualifier perplexed me a bit.
Again, thanks for your help.
Mark
"Han" wrote:
Mark
Wei's post looked funny on my OutlookExpress. re-written,
xmlcol.value('declare namespace t1=""; ()[1]', varchar(50)')
fill your namespace inside "" and xpath inside ().
Or
you can omit the namespace using wildcard, something like '*:test'.
Or use /with/
with xmlnamespace ('ns1' as ns1-alias) select
xcol.query('/descendant::ns1-alias:test') ...
Or with + default
with xmlnamespace (default 'ns1') select xcol.query('/descendant::test')
"Wei Lu [MSFT]" <weilu@xxxxxxxxxxxxxxxxxxxx> wrote in message
news:HLZF%23a%23IHHA.2024@xxxxxxxxxxxxxxxxxxxxxxxxx
Hello Mark,
I would like to suggest you use the following statement to have a try:
SELECT xml_col.value('declare namespace
t1="http://ex.org/test";(/t1:test',
'varchat(50)') from xml_test
Also, please post the xml value of the record in your table so that I
could
try to reproduce this issue on my side.
Here is the article for your reference:
value() Method (xml Data Type)
http://msdn2.microsoft.com/en-us/ms178030.aspx
Sincerely,
Wei Lu
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent
issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each
follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach
the
most efficient resolution. The offering is not appropriate for
situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are
best
handled working with a dedicated Microsoft Support Engineer by
contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
.
- References:
- RE: SQL2005, validation, & XQuery
- From: Wei Lu [MSFT]
- Re: SQL2005, validation, & XQuery
- From: Han
- Re: SQL2005, validation, & XQuery
- From: Mark
- RE: SQL2005, validation, & XQuery
- Prev by Date: Re: SQL2005, validation, & XQuery
- Next by Date: RE: Thoughts on storing address data with XML data type?
- Previous by thread: Re: SQL2005, validation, & XQuery
- Next by thread: Generate annotated XML schema from database structure
- Index(es):
Relevant Pages
|