¿Cómo puedo escapar de las comillas dobles en atributos en una cadena XML en T-SQL?
Pregunta bastante simple: Tengo un atributo en el que me gustaría tener comillas dobles. ¿Cómo puedo escapar de ellos? He intentado
- \"
- ""
- \\"
Y he hecho la variable @xml tanto xml type como varchar(max) para todos ellos.
declare @xml xml --(or varchar(max) tried both)
set @xml = '<transaction><item value="hi "mom" lol"
ItemId="106" ItemType="2" instanceId="215923801" dataSetId="1" /></transaction>'
declare @xh int
exec sp_xml_preparedocument @xh OUTPUT, @xml
insert into @commits --I declare the table, just removed it for brevity
select
x.*
from openxml(@xh,'/transaction/item')
WITH (
dataItemId int,
dataItemType int,
instanceId int,
dataSetId int,
value varchar(max)
) x
4 answers
¿No sería "
en xml? es decir,
"hi "mom" lol"
* * editar: * * probado; funciona bien:
declare @xml xml
set @xml = '<transaction><item value="hi "mom" lol"
ItemId="106" ItemType="2" instanceId="215923801" dataSetId="1" /></transaction>'
select @xml.value('(//item/@value)[1]','varchar(50)')
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2009-03-16 15:10:12
TSql escapa una comilla doble con otra comilla doble. Así que si quieres que sea parte de tu literal de cadena sql harías esto:
declare @xml xml
set @xml = "<transaction><item value=""hi"" /></transaction>"
Si desea incluir una cita dentro de un valor en el propio xml, utilice una entidad, que se vería así:
declare @xml xml
set @xml = "<transaction><item value=""hi "mom" lol"" /></transaction>"
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2009-03-16 15:14:37
Ya no puede hacer comentarios, pero votó y quería que la gente supiera que "
funciona muy bien para los archivos de configuración xml cuando se forman expresiones regex para RegexTransformer en Solr de la siguiente manera: regex=".*img src="(.*)".*"
usando la versión escapada en lugar de comillas dobles.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-09-14 19:52:41
En gelatina.core para probar una cadena literal se usaría:
<core:when test="${ name == 'ABC' }">
Pero si tengo que comprobar la cadena"Toy's R Us":
<core:when test="${ name == &quot;Toy's R Us&quot; }">
Sería así, si se permitieran las comillas dobles dentro:
<core:when test="${ name == "Toy's R Us" }">
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-09-23 13:04:13