XML 列提取 ![CDATA[ ]]
我正在运行以下查询以从 xml 列中提取数据...问题是如何提取 ![CDATA[""]] 之间的数据?
select
CAST(xml as xml).value('(//@nodeName)[1]','nvarchar(20)') as NodeName,
CAST(xml as xml).value('(//![CDATA [prdDetDesc]])[1]','nvarchar(225)') as DetDesc,
CAST(xml as xml).value('(//prdImg)[1]','nvarchar(1000)') as prdImage
from [dbo].[cmsContentXml])
我需要提取 [[""]] 之间存在的数据
提前致谢
I am running the below query to extract data from an xml column...question is how to extract data that is in between ![CDATA[""]] ?
select
CAST(xml as xml).value('(//@nodeName)[1]','nvarchar(20)') as NodeName,
CAST(xml as xml).value('(//![CDATA [prdDetDesc]])[1]','nvarchar(225)') as DetDesc,
CAST(xml as xml).value('(//prdImg)[1]','nvarchar(1000)') as prdImage
from [dbo].[cmsContentXml])
I need to extract data that is present between [[""]]
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
CDATA 部分没有什么特别的。
它还处理混合值。
结果:
编辑
从表而不是转换为 XML 的变量:
在此处尝试:https://data.stackexchange.com/stackoverflow/q/108293/
编辑2
您需要在查询中指定节点名称。您还必须决定是否应该将不同的节点放在同一列中,或者它们是否应该放在不同的列中。下面我将向您展示如何做到这两点。
There is nothing special with CDATA sections.
It also handles mixed values.
Result:
Edit
From a table instead of a variable with a cast to XML:
Try it here: https://data.stackexchange.com/stackoverflow/q/108293/
Edit 2
You need to specify the node names in the query. You also have to decide if you should have the different nodes in the same column or if they should be in different columns. Below I show you how you can do both.