Sql server XML仅在文本存在时查找和删除
因此,在M$SQL 2014企业数据库中使用以下内容:Sql server XML仅在文本存在时查找和删除,sql-server,xml,tsql,xml-parsing,Sql Server,Xml,Tsql,Xml Parsing,因此,在M$SQL 2014企业数据库中使用以下内容: DECLARE @table TABLE (XmlCol XML) INSERT INTO @table (XmlCol) VALUES (' <DEFeatureClassInfo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:typens="http://www.esri
DECLARE @table TABLE (XmlCol XML)
INSERT INTO @table (XmlCol) VALUES ('
<DEFeatureClassInfo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:typens="http://www.esri.com/schemas/ArcGIS/10.8" xsi:type="typens:DEFeatureClassInfo">
<GPFieldInfoExs xsi:type="typens:ArrayOfGPFieldInfoEx">
<GPFieldInfoEx xsi:type="typens:GPFieldInfoEx">
<Name>UNITCODE</Name>
<AliasName>UNITCODE</AliasName>
<ModelName>UNITCODE</ModelName>
<FieldType>esriFieldTypeString</FieldType>
<IsNullable>true</IsNullable>
<Required>true</Required>
</GPFieldInfoEx>
<GPFieldInfoEx xsi:type="typens:GPFieldInfoEx">
<Name>REGIONCODE</Name>
<AliasName>REGIONCODE</AliasName>
<ModelName>REGIONCODE</ModelName>
<DomainName>DOM_REGIONCODE_NPS2016</DomainName>
<FieldType>esriFieldTypeString</FieldType>
<DefaultValueString>SER</DefaultValueString>
<IsNullable>true</IsNullable>
<Required>true</Required>
</GPFieldInfoEx>
<GPFieldInfoEx xsi:type="typens:GPFieldInfoEx">
<Name>CREATEUSER</Name>
<AliasName>CREATEUSER</AliasName>
<ModelName>CREATEUSER</ModelName>
<FieldType>esriFieldTypeString</FieldType>
<DefaultValueString>GRSM User</DefaultValueString>
<IsNullable>true</IsNullable>
<Required>true</Required>
</GPFieldInfoEx>
</GPFieldInfoExs>
</DEFeatureClassInfo>')
这花费了我4个小时的谷歌搜索,并向我展示了数据库中至少有哪些表在XML模式定义中包含CREATEUSER。只需要触摸所有这些,并删除真正的。为了澄清,我不想删除true的其他实例。在上面发布的同一个示例中,我们看到UNITCODE节点中存在true,并且不能删除/删除true。我只想删除与CREATEUSER关联的true 请尝试以下操作 SQL
请根据输入XML共享所需的输出。准确运行解决方案并针对生产运行,将导致真正更改为。我怎样才能把它也处理掉呢?我需要删除整个true…和…SET XmlCol.modify'delete/defectureclassinfo/GPFieldInfoExs/GPFieldInfoEx[Name=CREATEUSER]/Required[1];我成功了!谢谢,你的例子给了我正确的方向!不清楚是需要1只删除元素的值,还是需要2完全删除整个元素。
<Required>true</Required>
<Required>true</Required>
<Name>CREATEUSER</Name>
SELECT *
FROM GDB_ITEMS
WHERE GDB_ITEMS.Definition.exist(N'//Name[text()="CREATEUSER"]') = 1;
-- DDL and sample data population, start
DECLARE @tbl TABLE (XmlCol XML)
INSERT INTO @tbl (XmlCol) VALUES
(N'<DEFeatureClassInfo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:typens="http://www.esri.com/schemas/ArcGIS/10.8"
xsi:type="typens:DEFeatureClassInfo">
<GPFieldInfoExs xsi:type="typens:ArrayOfGPFieldInfoEx">
<GPFieldInfoEx xsi:type="typens:GPFieldInfoEx">
<Name>UNITCODE</Name>
<AliasName>UNITCODE</AliasName>
<ModelName>UNITCODE</ModelName>
<FieldType>esriFieldTypeString</FieldType>
<IsNullable>true</IsNullable>
<Required>true</Required>
</GPFieldInfoEx>
<GPFieldInfoEx xsi:type="typens:GPFieldInfoEx">
<Name>REGIONCODE</Name>
<AliasName>REGIONCODE</AliasName>
<ModelName>REGIONCODE</ModelName>
<DomainName>DOM_REGIONCODE_NPS2016</DomainName>
<FieldType>esriFieldTypeString</FieldType>
<DefaultValueString>SER</DefaultValueString>
<IsNullable>true</IsNullable>
<Required>true</Required>
</GPFieldInfoEx>
<GPFieldInfoEx xsi:type="typens:GPFieldInfoEx">
<Name>CREATEUSER</Name>
<AliasName>CREATEUSER</AliasName>
<ModelName>CREATEUSER</ModelName>
<FieldType>esriFieldTypeString</FieldType>
<DefaultValueString>GRSM User</DefaultValueString>
<IsNullable>true</IsNullable>
<Required>true</Required>
</GPFieldInfoEx>
</GPFieldInfoExs>
</DEFeatureClassInfo>');
-- DDL and sample data population, end
-- before
SELECT * FROM @tbl;
DECLARE @NewValue VARCHAR(10) = '';
UPDATE @tbl
SET XmlCol.modify('replace value of
(/DEFeatureClassInfo/GPFieldInfoExs/GPFieldInfoEx[Name="CREATEUSER"]/Required/text())[1] with (sql:variable("@NewValue"))');
-- after
SELECT * FROM @tbl;