Reputation: 3293
Using Microsoft SQL Server...
declare @x xml
set @x = '<Example><You & Me></Example>'
select cast(@x.query('/Example/text()') as nvarchar(50))
The result is "<You & Me>" rather than "<You & Me>".
How can I have SQL read the XML in such as way that '<', '&' and '>' are decoded?
Upvotes: 3
Views: 3981
Reputation: 138980
Use value()
instead of query()
.
declare @x xml
set @x = '<Example><You & Me></Example>'
select @x.value('(/Example)[1]', 'nvarchar(50)')
Upvotes: 7