I'm trying to read an XML file from SQL Server. I think it's a problem with Namespace.. This is an example of my simple XML:
<?xml version="1.0"?>
-<ArrayOfStatistica xmlns:i="http://ift.tt/ra1lAU" xmlns="http://ift.tt/1rjwZus">-<Statistica><BuildFinale>68</BuildFinale><BuildIniziale>1</BuildIniziale><DataInserimento>2014-11-21T09:34:25.387</DataInserimento><IdCliente>-1</IdCliente><IdOperazione>4</IdOperazione><IdRivenditore>-1</IdRivenditore><IdTipoProdotto>-1</IdTipoProdotto><IdUtente>2</IdUtente><IdVersione>3</IdVersione></Statistica>-<Statistica><BuildFinale>68</BuildFinale><BuildIniziale>1</BuildIniziale><DataInserimento>2014-11-21T09:37:43.84</DataInserimento><IdCliente>-1</IdCliente><IdOperazione>4</IdOperazione><IdRivenditore>-1</IdRivenditore><IdTipoProdotto>-1</IdTipoProdotto><IdUtente>2</IdUtente><IdVersione>3</IdVersione></Statistica></ArrayOfStatistica>
With the following code:
;WITH XMLNAMESPACES ('http://ift.tt/1rjwZus"' AS ArrayOfStatistica)
SELECT
(SELECT Child.value('(IdStatistica)[1]', 'bigint')),
(SELECT Child.value('(IdUtente)[1]', 'int')),
(CASE WHEN Child.value('(IdRivenditore)[1]', 'int') = -1 THEN NULL else (SELECT Child.value('(IdRivenditore)[1]', 'int')) end),
(CASE WHEN Child.value('(IdCliente)[1]', 'int') = -1 THEN NULL else (SELECT Child.value('(IdCliente)[1]', 'int')) end),
(SELECT Child.value('(DataInserimento)[1]', 'datetime')),
(CASE WHEN Child.value('(IdTipoProdotto)[1]', 'int') = -1 THEN NULL else (SELECT Child.value('(IdTipoProdotto)[1]', 'int')) end),
(SELECT Child.value('(IdVersione)[1]', 'int')),
(SELECT Child.value('(BuildIniziale)[1]', 'bigint')),
(SELECT Child.value('(BuildFinale)[1]', 'bigint')),
(SELECT Child.value('(IdOperazione)[1]', 'int'))
FROM
@xmlfile.nodes('ArrayOfStatistica/Statistica') AS N(Child)
I do not get any value from SELECT.
How should I set the namespace for this xml file? If I remove the lines for the XML namespace (http://ift.tt/1rjwZus" xmlns: i = "http://ift.tt/tphNwY -instance ">) everything works fine.
No comments:
Post a Comment