Click here to Skip to main content
14,449,574 members
Rate this:
Please Sign up or sign in to vote.
CREATE TABLE [dbo].[tbl_UIConfig](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[PolicyName] [nvarchar](50) NULL,
	[XmlData] [xml] NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]


INSERT INTO [dbo].[tbl_UIConfig] VALUES('Policy1', '<main>
<mainUI>
<AppList>
<AppConfig>
	<AppSettings name="notepad" path="c:\Windows\System32\notepad.exe" />
	<AppDesignSettings appLogoName="notepad_534hjj45j35.png" />
</AppConfig>
<AppConfig>
	<AppSettings name="wordpad" path="C:\Program Files\Windows NT\Accessories\wordpad.exe" />
	<AppDesignSettings appLogoName="wordpad_nmb8mn98b908.png" />
</AppConfig>
<AppConfig>
	<AppSettings name="mspaint" path="c:\Windows\System32\mspaint.exe" />
	<AppDesignSettings appLogoName="mspaint_sdf9sd8f89sf.png" />
</AppConfig>
</AppList>
</mainUI>
</main>')

I have a table which contains XML column and this XML contains application details.
I want to do a functionality where if user delete image from Image Gallery then I want update this XML.

I want to update that image name to default one(defaultimg.png) in this XML. i.e. I want to update appLogoName atribute of AppDesignSettings element of every AppConfig element if appLogoName contains the same image which user has deleted.

The effect should be happen in every row of the table. and it should check every AppConfig node from AppList.

Please comment if you have any confusion.

Thanks.

What I have tried:

I have tried where only first matching record get update. But I want to update every matching item of AppList and from each table row XML.
Posted
Updated 2-Oct-18 2:47am

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

   
Comments
Maddy_1008 2-Oct-18 9:23am
   
Thanks for your reply. But I want to update every matching item of AppList and from each table row XML.

...
Thanks.
Eric Lynch 2-Oct-18 10:17am
   
The specified link provides an example where XML in multiple table rows is updated. Depending on your exact requirement, you need to either change, or omit, the WHERE clause in the SQL UPDATE. To change exactly what is updated in each XML document, you would need to adjust the XPATH selector.

As mentioned, in the response, its to "get you started"...not to write it for you.

Its unclear, from your response, if you're having trouble updating multiple SQL rows, trouble updating multiple XML elements (presumably within a column for each of those rows), or if you're conflating the two very different concepts.

If you're having trouble updating multiple SQL rows, you should become more familiar with the SQL UPDATE command, which makes this quite easy. See: https://www.w3schools.com/sql/sql_update.asp.

If you're having trouble understanding the XML data type methods, which allow you to play with XML text, see: https://docs.microsoft.com/en-us/sql/t-sql/xml/xml-data-type-methods?view=sql-server-2017.

If you're having trouble selecting multiple XML elements, to update, you should become more familiar with XPATH. See: https://www.w3schools.com/xml/xpath_syntax.asp.

All the parts you need are demonstrated in the original link (provided in the solution).

If you need someone to put all the parts together, and write it for you, its not really what Q&A is for, but you might still have some luck here. However, you'll need to provide a lot more detail in your question, for someone to do that.

You're more likely to get assistance, if you have some specific question about an element of the larger problem.

In any case, hope this helps you to either get started on a solution or clarify your question. Best of luck.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100