Solved

Adding node to XML data using Xquery

Posted on 2011-09-19
1
310 Views
Last Modified: 2012-05-12
Is there a way to add a node to an XML string using Xquery?

For example:

<node1>test1</node1>
<node2>test2</node2>

The XML string is stored in a SQL table so I would need to extract the string, add the node and save the string back to the table.

0
Comment
Question by:felkamau
1 Comment
 
LVL 59

Accepted Solution

by:
Kevin Cross earned 500 total points
ID: 36563757
felkamau,

Maybe you want to look at the insert capabilities of XML.modify() in SQL Server.
Here is an example:
DECLARE @xml XML;
SET @xml = '<node1>test1</node1><node2>test2</node2>';

SET @xml.modify('insert <node3>test3</node3> as last into (/)');

SELECT @xml;

Open in new window


Hope that helps!

Best regards and happy coding,

Kevin
0

Featured Post

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now