Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Other SQL Server Topics (2005)
 XML with two namespaces

Author  Topic 

doshim
Starting Member

1 Post

Posted - 2009-12-28 : 15:34:32
Hi,

I am having one xml file mentioned below and the data from this xml file needs to be exported to SQL Server 2005 table with the help of Stored Procedure. The SQL statement used in the Stored Procedure is mentioned below it.

The problem I am facing is that the SELECT statement returns NULL values for all the 3 columns. And the restriction is that I cannot make any changes to the XML file.


XML FILE
=========
<?xml version="1.0" ?>
<DeltaPublish xmlns="http://xmlns.oracle.com/Enterprise/Tools/schemas/DeltaPublish.VERSION_1"><HRData><PublishDate class="R" xmlns="http://xmlns.oracle.com/Enterprise/Tools/schemas/HRData.VERSION_1"><ProcessDate>2009-11-03</ProcessDate><Employee class="R"><EmployeeID>1</EmployeeID><LastName>xyz</LastName><FirstName>abc</FirstName></Employee><Employee class="R"><EmployeeID>2</EmployeeID><LastName>pqr</LastName><FirstName>def</FirstName></Employee></PublishDate></HRData></DeltaPublish>


SQL STATEMENT
================
create TABLE #WorkingTable (Data XML)

INSERT INTO #WorkingTable
SELECT *
FROM OPENROWSET(BULK '<xmlfilename>',SINGLE_BLOB) AS data

DECLARE @XML AS XML, @hDoc AS INT

SELECT @XML = Data
FROM #WorkingTable

EXEC sp_xml_preparedocument @hDoc OUTPUT , @XML , '<DeltaPublish xmlns:myns="http://xmlns.oracle.com/Enterprise/Tools/schemas/DeltaPublish.Version_1" />'

SELECT
EmployeeID, LastName, FirstName
FROM OPENXML(@hDoc, '/myns:DeltaPublish/myns:HRData/myns:PublishDate/myns:Employee/',2)
WITH (EmployeeID NUMERIC 'myns:EmployeeID',
LastName VARCHAR(50) 'myns:LastName',
FirstName VARCHAR(50) 'myns:FirstName')


Regards
Mehul Doshi
New Jersey, USA


sql-programmers
Posting Yak Master

190 Posts

Posted - 2010-01-16 : 03:50:16
Hi,

I have a blog article , it me be assist you with your question:

http://www.sql-programmers.com/Blog/tabid/153/EntryId/10/XML-Data-Type-in-SQL-Server-2005.aspx


SQL Server Programmers and Consultants
http://www.sql-programmers.com/
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2010-01-16 : 03:54:07
See
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=123365
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=113872



N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page
   

- Advertisement -