removing a node from xml data type

HI All,

Please consider the folowing data in an xml data type

<Entity name="Category">
  <Column name="Updated" type="datetime2" nullable="1">
    <Properties>
      <Hide />
    </Properties>
  </Column>
</Entity>

I need to remove all Column nodes that have a Hide node descendant resulting in the folowing xml:

<Entity name="Category">
 </Entity>

But I am unable to find the correct xpath syntax to do so.

SET @xmlResult.modify('delete (//Hide/parent()/parent())');
results in an error when trying to alter the stored procedure
XQuery [modify()]: The XQuery syntax '/function()' is not supported

SET @xmlResult.modify('delete (//Hide/../..)');
results in
XQuery [modify()]: Only non-document nodes may be deleted, found 'element(*,xdt:untyped) | document { (element(*,xdt:untyped) ? & text ? & comment ? & processing-instruction ?) * }'

Any ideas?

Regards
LVL 2
DaFouAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Anthony PerkinsCommented:
Try it this way:
SET @XmlResult =
'<Entity name="Category">
  <Column name="Updated" type="datetime2" nullable="1">
    <Properties>
      <Hide Test="1"/>
    </Properties>
  </Column>
</Entity>'

SET @XmlResult.modify('delete if (count(/Entity/Column/Properties/Hide)>0) then /Entity/Column[1] else ()')
SELECT @XmlResult

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Anthony PerkinsCommented:
Let's try that again:
DECLARE @XmlResult Xml

SET @XmlResult =
'<Entity name="Category">
  <Column name="Updated" type="datetime2" nullable="1">
    <Properties>
      <Hide/>
    </Properties>
  </Column>
</Entity>'

SET @XmlResult.modify('delete if (/Entity/Column/Properties/Hide) then /Entity/Column[1] else ()')
SELECT @XmlResult

Open in new window

0
DaFouAuthor Commented:
the first worked as well. thx alot

Regards
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2008

From novice to tech pro — start learning today.