Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3623888
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T23:26:21+00:00 2026-05-18T23:26:21+00:00

Is it possible to use an XML DML statement to rename an element in

  • 0

Is it possible to use an XML DML statement to rename an element in an untyped XML column?

I am in the process of updating an XML Schema Collection on an XML column and need to patch the existing XML instances by renaming one element before I can apply the latest schema.

As far as I can tell from the docs you can only insert / delete nodes or replace their value.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T23:26:21+00:00Added an answer on May 18, 2026 at 11:26 pm

    As the saying goes, “Where there’s a will there’s a way”

    Here’s two methods:
    the first is to simply replace the previous xml with a new xml constructed from the original with the new element name. In my example I’ve changed Legs/Leg to Limbs/Limb this could get very complicated for anything but the simplest schema

    And secondly, a more appropriate approach of combining insert and delete.

    I’ve combined them into one simple example:

    declare @xml as xml = '<animal species="Mouse">
      <legs>
        <leg>Front Right</leg>
        <leg>Front Left</leg>
        <leg>Back Right</leg>
        <leg>Back Left</leg>
      </legs>
    </animal>'
    
    set @xml = (select 
         t.c.value('@species', 'varchar(max)') as '@species'
        ,(select
         ti.C.value('.', 'varchar(max)') 
    from @Xml.nodes('//animal/legs/leg') ti(c) for xml path('limb'), /* root('limb'), */type) as    limbs   
    from @xml.nodes('//*:animal') t(c) for xml path('animal'), type)
    
    select @xml;
    
    while (@xml.exist('/animal/limbs/limb') = 1) begin
        /*insert..*/
        set @xml.modify('
                insert <leg>{/animal/limbs/limb[1]/text()}</leg>
                before (/animal/limbs/limb)[1]
            ');
        /*delete..*/
        set @xml.modify('delete (/animal/limbs/limb)[1]');
    end
    
    set @xml.modify('
            insert <legs>{/animal/limbs/leg}</legs>
            before (/animal/limbs)[1]
        ');
    set @xml.modify('delete (/animal/limbs)[1]');
    
    select @xml;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to use a XML element from other file in another XML?
Is it possible to use xml schema to express somme rules for other schemas
Is it possible to use the XML Schema validation and XMLSerializer together? My project
Is it possible to use a hbm xml Hibernate configuration to build an EntityManagerFactory
Is it possible to use the Open XML sdk to manipulate parts of document
Is it possible to use a JavaScript plugin to open and save an XML
Is it possible for the XML output of one CGI script to make use
Possible Duplicate: Enforcing spaces in string resources This is the strings.xml file I use
Is it possible to draw a shape in xml, and use a png as
I need a control having these features: It should be possible use it in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.