I'm using a fairly straightforward Xpath query (below) to query a SQL Server 2008 database column whose values all follow the form of the example (below that). My query returns NULL
for all rows, rather than the values of the example
attribute (e.g. "VALUE"), even though the example
attribute is defined for every row I'm querying.
I've tried declaring the xsd
and xsi
namespaces in my Xquery expression, and selecting from multiple different attribute names, but neither had any effect. What am I missing?
Query:
select ColumnName.value('(/RootNode/@example)[1]', 'nvarchar(15)') [Result]
from TableName
XML sample node (actual XML contains many more attributes, which I've omitted):
<RootNode xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://intranet"
example="VALUE">
<IsValid>true</IsValid>
</RootNode>
Attempted query using namespaces, with same result:
select ColumnName.value('
declare namespace xsd="http://www.w3.org/2001/XMLSchema";
declare namespace xsi="http://www.w3.org/2001/XMLSchema-instance";
(/RootNode/@example)[1]', 'nvarchar(15)') [Result]
from TableName
xsi
orxsd
, but the default set one,http://intranet
– Sten Petrovxsd
andxsi
won't make difference, the default namespace will. I'm having trouble also decyphering your xpath. Looks like you're looking to retrieveIsValid
for aRootNode
that has@example
, which would be//RootNode[@example]/IsValid
– Sten Petrov