Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server 从XML中选择元素_Sql Server_Xml_Sql Server 2008_Xpath - Fatal编程技术网

Sql server 从XML中选择元素

Sql server 从XML中选择元素,sql-server,xml,sql-server-2008,xpath,Sql Server,Xml,Sql Server 2008,Xpath,鉴于以下情况: declare @samplexml as xml set @samplexml = '<root><someelement><another /><somethingElse>test</somethingElse></someelement></root>' select @samplexml.value('/root[1]','nvarchar(max)') 但是我得到了错误VALU

鉴于以下情况:

declare @samplexml as xml
set @samplexml = '<root><someelement><another /><somethingElse>test</somethingElse></someelement></root>'

select
  @samplexml.value('/root[1]','nvarchar(max)')
但是我得到了错误
VALUE方法中使用的数据类型“XML”无效。

只需使用
.query()
方法,而不是
.VALUE()


这将返回与给定XPath表达式匹配的元素(及其内容),并以
XML
type

的形式返回。是否尝试获取作为输入的完整XML?
select
  @samplexml.value('/root[1]','XML')
SELECT @samplexml.query('/root[1]')
SELECT @samplexml.query('.')