> Hi all,
>
> I'm parsing an xml data type to import those data into a table. My current
> approach is:
>
> Declare @xDoc Xml
> Set @xDoc = some xml
> Set @sReferenciaID = @xDoc.value('declare namespace
> ns="http://Homex.WS.FacturacionElectronica.DataTypes/2007/12";
> /ns:OrdenAceptacion/ns:Addenda/ns:ReferenciaID)[1]', 'varchar(max)')
> Set @sAlmacenCodigo = @xDoc.value('declare namespace
> ns="http://Homex.WS.FacturacionElectronica.DataTypes/2007/12";
> (/ns:OrdenAceptacion/ns:Addenda/ns:AlmacenCodigo)[1]', 'varchar(max)')
> ...
>
> But there are dozens of such fields! It is a little boring to type all that
> stuff, specially the namespace over and over again. May be is it another
> more compact way to write this?
WITH XMLNAMESPACES
('http://Homex.WS.FacturacionElectronica.DataTypes/2007/12' as ns)
SELECT
T.a.value('ns:ReferenciaID[1]', 'nvarchar(200)') AS ReferenciaID,
T.a.value('ns:ns:AlmacenCodigo[1]', 'nvarchar(200)') AS AlmacenCodigo
FROM
xDoc.nodes('/ns:OrdenAceptacion/ns:Addenda') T(a);