Solved

Adding node to XML data using Xquery

Posted on 2011-09-19
1
293 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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

743 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

18 Experts available now in Live!

Get 1:1 Help Now