Wednesday, March 28, 2012

How can I read value from one XML and assign to another XML.

I need to read value from one master XML and assign to another XML.

I am planning to move some of my application's business logic to SQL Server side.

I have informations stored in xml field. There is a procedure which accepts the xml input, and return the xml with values from the master xml. Please help me to achieve this.

-- master XML

declare @.x_master xml

set @.x_master='<ROOT><NAME>111</NAME><ADDRESS>2222</ADDRESS><TYPE>3333</TYPE><COUNTRY/></ROOT>'

-- input XML (this can be any tag from the master XML)

declare @.x xml

set @.x='<ROOT><NAME></NAME><ADDRESS/></ROOT>'

--set @.x='<ROOT><NAME/><COUNTRY/></ROOT>'

--set @.x='<ROOT><ADDRESS/><COUNTRY/><TYPE/></ROOT>'

It sounds like you want to interpret <ROOT><NAME></NAME><ADDRESS/></ROOT> as a query. You could generate XQuery by concatenating strings together. You could insert path expressions into the context of <NAME></NAME>. But you need to make sure it is safe from SQL injection since you will be dynamically constructing SQL/XQuery using string concatenation.

sql

No comments:

Post a Comment