June 18, 2007 at 10:05 am
Hi Guys,
I have a stored proc that is returning XML to the client, as listed below.
The question I have is that the description field can contain some HTMLa and possibly some illegal XML characters i.e &,<,>, ' etc.
I would like to wrap these sections in a CDATA field but am a little unsure how to do it.
Oh yeah the XML is going to be transformed by XSLT on the client.
Any tips would be greatly appreciated.
Ideally what I would like to achieve is to get rid of calling my DBO.HTMLENcode function I have written to encode the illegal characters.
Select @Brief as briefdescription,
Cast('
cast('
cast(price as money) as price, bedrooms as bedroom, status_id,
cast(replace(('
Size_metre_sq as sqm,
COALESCE (ADDRESS1 + ', ', '') + COALESCE (ADDRESS2 + ', ', '') + COALESCE (ADDRESS3 + ', ',
'') + COALESCE (ADDRESS4, '') AS Address ,directions ,
Saleterms.SALETERMS as saleterm ,Saleterms.price_label as PriceLabel, leaseterms, rating,
Convert(varchar(11) ,Availability, 113) as availability
from dbo.PROPERTY as Property
inner join Saleterms on Property.Saleterms_ID = Saleterms.ID
where Property.id = @id
FOR XML PATH('Property'), ROOT('Detail')
Gary Woodfine
threenineconsulting.com
June 18, 2007 at 10:25 am
You have to use XML EXPLICIT and specify CDATA for each column you want.
SELECT
1AS TAG,
NULLAS parent,
'Some <XML'AS [X!1!SourceID!CDATA]
FROM
DataSource AS X
FOR XML EXPLICIT
Cheers,CrispinI can't die, there are too many people who still have to meet me!It's not a bug, SQL just misunderstood me!
June 18, 2007 at 10:35 am
I don't understand?
do you have a reference I can look at?
Gary Woodfine
threenineconsulting.com
June 18, 2007 at 1:47 pm
Only FOR XML EXPLICIT supports CDATA. You'll have to look in BOL for FOR XML EXPLICIT for some examples.
For the query you have, it is nothing major to convert. Let me know if you don't come right...
Cheers,CrispinI can't die, there are too many people who still have to meet me!It's not a bug, SQL just misunderstood me!
Viewing 4 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply