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

more...

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

Group: microsoft.public.sqlserver.xml · Group Profile
Author: Martin Honnen
Date: Sep 13, 2008 03:45

SammyBar wrote:
> 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?

Check the
with xmlnamespaces
clause
http://msdn.microsoft.com/en-us/library/ms177607(SQL.90).aspx
then you can use

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);

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
no comments
diggit! del.icio.us! reddit!