Home > Archive > MS SQL XML > September 2005 > Is it possible to rename element using xquery in sql 2005?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Is it possible to rename element using xquery in sql 2005?
firechaser@talk21.com

2005-09-06, 3:24 am

I'd like to be able to rename the element 'transport' to 'vehicles'

<transport>
<cars />
<tractors />
<buses />
<planes />
</transport>

|
|
V

<vehicles>
<cars />
<tractors />
<buses />
<planes />
</vehicles>

Is this possible via sql 2005's subset of xquery?

I thought about copying the attributes & elements of <transport> into a
new element called 'vehicles' inserting it above <transport> and then
deleting the latter but isn't that a bit clunky especially if
<transport> has thousands of nodes? It would mean a lot of unneccesary
processing and copying in/out ram just to change two strings i.e.
opening and closing element tags.

Anyone with ideas?

Thanks,
Peter

Michael Rys [MSFT]

2005-09-06, 1:25 pm

Do you need to do a transformation or an in-place replace?

In either case, you would need to use XQuery in the following way:

Let's assume that the XML is in a variable @x:

select @x.query('<vehicles>{/transport/node()}</vehicles>')

would do the transform.

set @x = @x.query('<vehicles>{/transport/node()}</vehicles>')

(applying the above to table columns and adding support for attributes is
left as an exercise to the reader).

We do not have a rename functionality in the DML in this release.

Best regards
Michael

<firechaser@talk21.com> wrote in message
news:1125992983.590477.141270@g44g2000cwa.googlegroups.com...
> I'd like to be able to rename the element 'transport' to 'vehicles'
>
> <transport>
> <cars />
> <tractors />
> <buses />
> <planes />
> </transport>
>
> |
> |
> V
>
> <vehicles>
> <cars />
> <tractors />
> <buses />
> <planes />
> </vehicles>
>
> Is this possible via sql 2005's subset of xquery?
>
> I thought about copying the attributes & elements of <transport> into a
> new element called 'vehicles' inserting it above <transport> and then
> deleting the latter but isn't that a bit clunky especially if
> <transport> has thousands of nodes? It would mean a lot of unneccesary
> processing and copying in/out ram just to change two strings i.e.
> opening and closing element tags.
>
> Anyone with ideas?
>
> Thanks,
> Peter
>



Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2008 droptable.com