Boring parsing multiple fields from the same namespace...
  Home FAQ Contact Sign in
microsoft.public.sqlserver.xml only
 
Advanced search
POPULAR GROUPS

more...

 Up
Boring parsing multiple fields from the same namespace...         

Group: microsoft.public.sqlserver.xml · Group Profile
Author: SammyBar
Date: Sep 12, 2008 10:23

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?

I feel should be something like:

Declare @ns namespace
Set @ns = 'http://Homex.WS.FacturacionElectronica.DataTypes/2007/12'
Select '/ns:OrdenAceptacion/ns:Addenda/ns:ReferenciaID)[1]' As ReferenciaID
,'/ns:OrdenAceptacion/ns:Addenda/ns:AlmacenCodigo)[1]' As AlmacenCodigo
From @xDoc

Or may be something less radical like:

Declare @ns namespace
Set @ns = 'http://Homex.WS.FacturacionElectronica.DataTypes/2007/12'
Set @sReferenciaID =
@xDoc.value('/ns:OrdenAceptacion/ns:Addenda/ns:ReferenciaID)[1]',
'varchar(max)', @ns)

What do you think?
Any hint is welcomed

Thanks in advance
Sammy
2 Comments
diggit! del.icio.us! reddit!