2015-07-20 55 views
-1

因此,例如在SQLSERVER使用XPath我如何返回标签的所有混合内容

选择这个节点

<p> 
    This is an open access article under the terms of the 
    <url href="http://creativecommons.org/licenses/by-nc-nd/3.0/">Creative Commons Attribution‐NonCommercial‐NoDerivs</url> 
    License, which permits use and distribution in any medium, provided the original work is properly cited, the use is non‐commercial and no modifications or adaptations are made. 
</p> 

根本就与我想保持一个URL标记文本这样

目前我可以用选择一切从它下面的SQL

select 
    isnull(pMetaUnitlegal.value('(*:p/node())[1]','varchar(255)') ,'') 
    + isnull(pMetaUnitlegal.value('(*:p/node())[2]','varchar(255)') ,'') 
    + isnull(pMetaUnitlegal.value('(*:p/node())[3]','varchar(255)') ,'') legal_statement 
from XMLwithOpenXML 
OUTER APPLY XMLData.nodes('/*:component/*:header/*:publicationMeta[@level = "unit"]/*:legalStatement') pmul(pMetaUnitlegal) 

和我得到

这是在知识共享署名 - 非商业性使用 - 禁止演绎许可,允许在任何媒体的使用和分配方面的开放获取文章,提供原工作正确引用,使用是非商业和不做任何修改或改编。

但我真正想要的是

<p> 
    This is an open access article under the terms of the 
    <url href="http://creativecommons.org/licenses/by-nc-nd/3.0/">Creative Commons Attribution‐NonCommercial‐NoDerivs</url> 
    License, which permits use and distribution in any medium, provided the original work is properly cited, the use is non‐commercial and no modifications or adaptations are made. 
</p> 

与嵌入式仍然

当我使用text()评估我得到较少的数据的HTML标签。 url节点完全丢失

这是一个开放获取的条款下的许可条款,允许使用和分发在任何媒体,只要原始作品被适当引用,使用非商业和不修改或改编。

任何建议将非常受欢迎。

这些数据将从网页上的数据库中显示出来,所以如果我可以保存html标记以便使用,那将是非常好的。

回答

0

您可以尝试使用XML的方法query()代替value()获得的原始XML数据,例如:

select 
    CONVERT(VARCHAR(MAX), pMetaUnitlegal.query('*:p')) legal_statement 
from XMLwithOpenXML 
OUTER APPLY 
    XMLData.nodes('/*:component/*:header/*:publicationMeta[@level = "unit"]/*:legalStatement') pmul(pMetaUnitlegal) 

这是演示工作示例:

declare @xml XML = '<p> 
    This is an open access article under the terms of the 
    <url href="http://creativecommons.org/licenses/by-nc-nd/3.0/">Creative Commons Attribution‐NonCommercial‐NoDerivs</url> 
    License, which permits use and distribution in any medium, provided the original work is properly cited, the use is non‐commercial and no modifications or adaptations are made. 
</p>' 

select CONVERT(VARCHAR(MAX), @xml.query('p')) 

Sqlfiddle Demo

+0

嗨har07。这很好用,谢谢你的帮助。 – drinky

+0

@ user3268030不客气:)不要忘记[接受](http://meta.stackexchange.com/a/5235)这个答案然后 – har07

相关问题