Re: SQL2005, validation, & XQuery

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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.)






.



Relevant Pages

  • RE: Add Namespaces with XmlTextReader and XmltextWriter?
    ... Microsoft MSDN Online Support Lead ... Add Namespaces with XmlTextReader and XmltextWriter? ... Regarding on the question about add namespace into certain element in XML ...
    (microsoft.public.dotnet.framework)
  • Re: Need help with PHP DOMXML - get_elements_by_tagname
    ... PHP as a supported platform. ... uses the built in XML handler CF MX provides. ... in newer versions of PHP and the method will *not* support xpath. ...
    (comp.lang.php)
  • Re: namespace?
    ... Namespaces are used in XML (which is the format that your web service ... an XML namespace should start with the ACTUAL URL of your ... Microsoft MSDN Online Support Lead ...
    (microsoft.public.dotnet.framework.webservices)
  • Re: SQL2005, validation, & XQuery
    ... The xml in my sample columns only *had* one node: ... with the query I thought it might be related to the default namespace so I ... Microsoft Online Community Support ... where an initial response from the community or a Microsoft Support ...
    (microsoft.public.sqlserver.xml)
  • Re: Simple xpath query with default namespace
    ... query (a prefix that's no actually in the xml) in order for the library ... whether it's the default namespace. ... then when you have your XPath query you will need to tell XPath which Account ...
    (microsoft.public.dotnet.languages.csharp)