问题描述
我有一个名为XML的表(在SQL Server 2008中),并且有一个名为XmlDocument
的类型为XML
的字段.我正在尝试从XML变量中删除属性.
I have a table called XML (in SQL Server 2008) and it has a field called XmlDocument
of type XML
. I am trying to to delete an attribute from an XML variable.
这是我的xml的样子
<clue_personal_auto xmlns="http://cp.com/rules/client">
<admin>
<receipt_date>03/16/2011</receipt_date>
<date_request_ordered>03/16/2011</date_request_ordered>
<report_usage>Personal</report_usage>
</admin>
</clue_personal_auto>
我的查询
UPDATE XML
SET XmlDocument.modify('delete (/clue_personal_auto/@xmlns)[1]')
WHERE xmlid = 357
当我在查询分析器中运行此查询时,看到消息受影响的1行",但实际上并未删除clue_personal_auto元素的xmlns属性.不知道我在做什么错.
When I run this query in query analyzer I see the message "1 row(s) affected" but in reality the xmlns attribute of clue_personal_auto element is not being removed. Any idea what am I doing wrong.
谢谢BB
推荐答案
我似乎找不到一种简便的方法-但真正的问题仍然存在:为什么,您想删除吗命名空间?使用WITH XMLNAMESPACES ...
构造,您可以轻松使用命名空间.
I can't seem to find an easy way to do this - but the real question remains: why do you want to remove the namespace?? Using the WITH XMLNAMESPACES ...
construct, you can easily make use of the namespaces.
与其花费大量精力消除它,不如了解XML命名空间并开始使用它们!
Instead of putting a lot of effort in getting rid of it - learn about XML namespaces and start using them!
您可以在查询中轻松使用该XML名称空间:
You can quite easily use that XML namespace in your queries:
;WITH XMLNAMESPACES (DEFAULT 'http://cp.com/rules/client' )
SELECT
XmlDocument.value('(/clue_personal_auto/admin/report_usage)[1]', 'varchar(25)')
FROM XML
WHERE ID = 357
并对此感到满意-不再需要人为地删除xmlns=
声明!
and be happy with it - no need to artificially remove xmlns=
declarations anymore!
这篇关于如何从SQL Server 2008中的XML变量中删除属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!