Tengo algunas dudass
| |||
| seguramente no buscas bien , aqui un ejemplo basado en la documentaciondeclare @foo xml set @foo = '<?xml version="1.0" encoding="ISO-8859-1"?> <bookstore> <book> <title lang="en">Harry Potter</title> <author>J K. Rowling</author> <year>2005</year> <price>29.99</price> </book> </bookstore>' -- Reemplazar el valor del atributo 'lang' del nodo 'title' set @foo.modify (' replace value of (/bookstore/book/title/@lang)[1] with "test" ') -- Reemplazar el valor del nodo 'author' set @foo.modify (' replace value of (/bookstore/book/author/text())[1] with "Autor" ') select @foo |
| ||||
| XML es junto con la replicación, de los temas que tengo pendientes por experimentar con SQL Server...
__________________ Friedrich Nietzsche |
| ||||
| Cita: eje!! no había pasado por allí. Gracias.
Iniciado por foo seguramente no buscas bien , aqui un ejemplo basado en la documentaciondeclare @foo xml set @foo = '<?xml version="1.0" encoding="ISO-8859-1"?> <bookstore> <book> <title lang="en">Harry Potter</title> <author>J K. Rowling</author> <year>2005</year> <price>29.99</price> </book> </bookstore>' -- Reemplazar el valor del atributo 'lang' del nodo 'title' set @foo.modify (' replace value of (/bookstore/book/title/@lang)[1] with "test" ') -- Reemplazar el valor del nodo 'author' set @foo.modify (' replace value of (/bookstore/book/author/text())[1] with "Autor" ') select @foo Aunque hay algo que no entiendo: mis xml's tienen sus valores entre comillas dobles y el que tu muestras no tiene comillas, y el tag title tiene dos valores en la que no entiendo su sintaxis
Código:
<title lang="en">Harry Potter</title> <author>J K. Rowling</author> Cita: Orale!! no sabía. Pensaba que tu sabías de todo |
| |||
| Cita: http://www.w3schools.com/xml/xml_elements.asp
Iniciado por Developer9 eje!! no había pasado por allí. Gracias. Aunque hay algo que no entiendo: mis xml's tienen sus valores entre comillas dobles y el que tu muestras no tiene comillas, y el tag title tiene dos valores en la que no entiendo su sintaxis
Código:
<title lang="en">Harry Potter</title> <author>J K. Rowling</author> http://www.w3schools.com/xml/xml_attributes.asp |
| ||||
| Gracias amigo foo por toda la información. Aunque no entendí todas las diferencias y para que se usa cada cosa porque está en el idioma gringo ![]() Lo que necesitaba era modificar los atributos |
| ||||
| Cita:
Iniciado por foo seguramente no buscas bien , aqui un ejemplo basado en la documentaciondeclare @foo xml set @foo = '<?xml version="1.0" encoding="ISO-8859-1"?> <bookstore> <book> <title lang="en">Harry Potter</title> <author>J K. Rowling</author> <year>2005</year> <price>29.99</price> </book> </bookstore>' -- Reemplazar el valor del atributo 'lang' del nodo 'title' set @foo.modify (' replace value of (/bookstore/book/title/@lang)[1] with "test" ') select @foo HOla de nuevo foo Estaba trabajando con esto de la actualizacion del xml y la funcion modify solo me permite utilizar cadenas de caracteres pero no me permite concatenar. En tu ejemplo reemplazas el atributo del nodo @lang con la palabra 'test'. Pero que pasa si yo lo quiero reemplazar con el valor de algúna variable, no me deja concatenar! Estoy tratando de hacer esto:
Código:
Y me sale el siguiente error en la linea en negrita:declare @XmlCierraOrdenIngreso as xml
declare @VL_IdEmpresa as int
set @VL_IdEmpresa=99
set @XmlCierraOrdenIngreso='<?xml version="1.0" encoding="iso-8859-1"?><Usuario><ResultSet><Cabecera IdEmpresa="" IdOficina="" NumDocumento="" OrigenDocumentoInv="1"/><Detalle><Items IdDocumento="8"/><Items IdDocumento="7"/></Detalle></ResultSet></Usuario>'
SELECT @XmlCierraOrdenIngreso
SET @XmlCierraOrdenIngreso.modify('replace value of (/Usuario/ResultSet/Cabecera/@IdEmpresa)[1] with "' + convert(varchar(max),@VL_IdEmpresa) + '"')
--SET @XmlCierraOrdenIngreso.modify('replace value of (/Usuario/ResultSet/Cabecera/@IdEmpresa)[1] with "96"')
SELECT @XmlCierraOrdenIngreso
The argument 1 of the xml data type method "modify" must be a string literal. Creo estar concatenando dos cosas string. Y si comento aquella linea y utilizo la linea siguiente, utilizando el valor 96 si funciona, si solo funciona así no tiene chiste Alguna ayudita |