SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


XML Workshop 25 - Inserting elements and attributes to an XML document


XML Workshop 25 - Inserting elements and attributes to an XML document

Author
Message
jacob sebastian
jacob sebastian
SSCarpal Tunnel
SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)

Group: General Forum Members
Points: 4722 Visits: 2523
Comments posted to this topic are about the item XML Workshop 25 - Inserting elements and attributes to an XML document

.
Paul White
Paul White
SSC Guru
SSC Guru (61K reputation)SSC Guru (61K reputation)SSC Guru (61K reputation)SSC Guru (61K reputation)SSC Guru (61K reputation)SSC Guru (61K reputation)SSC Guru (61K reputation)SSC Guru (61K reputation)

Group: General Forum Members
Points: 61368 Visits: 11397
Another great instalment.

One thing for the section on inserting the contents of an XML variable when using 2005: there is a good workaround by Denis Ruckebusch here.



Paul White
SQLPerformance.com
SQLblog.com
@SQL_Kiwi
SQLRNNR
SQLRNNR
SSC Guru
SSC Guru (111K reputation)SSC Guru (111K reputation)SSC Guru (111K reputation)SSC Guru (111K reputation)SSC Guru (111K reputation)SSC Guru (111K reputation)SSC Guru (111K reputation)SSC Guru (111K reputation)

Group: General Forum Members
Points: 111904 Visits: 18624
Nice article. Thanks



Jason AKA CirqueDeSQLeil
I have given a name to my pain...
MCM SQL Server, MVP


SQL RNNR

Posting Performance Based Questions - Gail Shaw

Brad Schulz
Brad Schulz
SSC-Enthusiastic
SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)

Group: General Forum Members
Points: 186 Visits: 305
Wow! Excellent stuff, Jacob.
jacob sebastian
jacob sebastian
SSCarpal Tunnel
SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)

Group: General Forum Members
Points: 4722 Visits: 2523
Thank you Paul, Jason and Brad. I am glad to know that you liked it.

.
fabio.sorci
fabio.sorci
SSC Rookie
SSC Rookie (40 reputation)SSC Rookie (40 reputation)SSC Rookie (40 reputation)SSC Rookie (40 reputation)SSC Rookie (40 reputation)SSC Rookie (40 reputation)SSC Rookie (40 reputation)SSC Rookie (40 reputation)

Group: General Forum Members
Points: 40 Visits: 31
Hello jacob

The question is this:
I need to add a progressive for each element of an XML document. I read your two interesting articles "XML Workshop 25" and "XML Workshop XVII - Writing a LOOP to process XML elements in TSQL" and merged the two.

The problem is this:
Until I have a few XML elements from loop (say up to 10) all right, but increasing the processing is very slow so that I stop.

xml docoment:

<flsProSoc>
<Accesso>
<Identificativo>2008123456789000</Identificativo>
<Erogatore>
<CodiceIstituto>010ABAZZ</CodiceIstituto>
</Erogatore>
<Entrata>
<Data>2008-03-18</Data>
<Ora>09:30</Ora>
</Entrata>
<!--
many other XML elements and subelements XML
-->
</Accesso>
.......................................
.......................................
</flsProSoc>



Code:

DECLARE @max INT, @i INT, @xml XML
SELECT @xml=
(SELECT * FROM OPENROWSET(BULK
'C:\MYXML.xml'
, SINGLE_BLOB) as x)
SELECT
@max = @xml.query('<e>
{ count(/flsProSoc/Accesso) }
</e>').value('e[1]','int')
SET @i = 1
WHILE @i <= @max BEGIN
SET @xml.modify('
insert element MyId {sql:variable("@i")}
as first
into (flsProSoc/Accesso[position()=sql:variable("@i")])[1]
')
SET @i = @i + 1
END



I thank you in advance for your interest
jacob sebastian
jacob sebastian
SSCarpal Tunnel
SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)

Group: General Forum Members
Points: 4722 Visits: 2523
I think the performance is bad here for two reasons: loops and UNTYPED XML. In most cases, loops give bad performance. Since the XML document being processed is not TYPED XML, the processing overhead will be comparatively more.

.
fabio.sorci
fabio.sorci
SSC Rookie
SSC Rookie (40 reputation)SSC Rookie (40 reputation)SSC Rookie (40 reputation)SSC Rookie (40 reputation)SSC Rookie (40 reputation)SSC Rookie (40 reputation)SSC Rookie (40 reputation)SSC Rookie (40 reputation)

Group: General Forum Members
Points: 40 Visits: 31
Hi Jacob
Typed XML want to XSD schema associated, right?
I try to see if it improves performance.
Where do I specify the XSD file?
There is another solution to my problem always returns within TSQL?
Thanks again
jacob sebastian
jacob sebastian
SSCarpal Tunnel
SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)

Group: General Forum Members
Points: 4722 Visits: 2523
In SQL Server, you cannot specify XSD file to create a TYPED XML document, instead you need to create an XML SCHEMA Collection and then associate an XML document with a schema collection.

The following articles might help you to get started with XML Schema Collections:
http://beyondrelational.com/blogs/jacob/archive/2009/03/15/sql-server-xsd-typed-xml-and-schema-collections.aspx
http://beyondrelational.com/blogs/jacob/archive/2009/03/10/sql-server-xsd-validating-values-with-schema.aspx

.
pham_p
pham_p
Grasshopper
Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)

Group: General Forum Members
Points: 18 Visits: 204
Excellent article. I've been wondering on what is the best approach for updating an XML field data given another XML field with the same schema.

Thanks
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum







































































































































































SQLServerCentral


Search