By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,898 Members | 1,169 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,898 IT Pros & Developers. It's quick & easy.

XMl Import

P: 2
sir,

I Have a Problem in xml data importing Plese help me in this .
when i m insertning data through Application it is inserting but while I am using Store Procedure its giving the error

Running [dbo].[sp_xmlbulkinsert] ( @xmldata = D:\xml\rfid\Branches.xml, @table_name = Branches, @Action = xmlImport ).

The XML parse error 0xc00ce556 occurred on line number 1, near the XML text "D:\xml\rfid\Branches.xml".
The error description is 'Invalid at the top level of the document.'.
sp_xml_removedocument: The value supplied for parameter number 1 is invalid.
No rows affected.

And my SP is



Expand|Select|Wrap|Line Numbers
  1. set ANSI_NULLS ON
  2. set QUOTED_IDENTIFIER ON
  3. GO
  4.   ALTER PROC [dbo].[sp_xmlbulkinsert] 
  5.    @xmldata varchar(max) =null,
  6.    @table_name varchar(50),
  7.    @Action varchar(50)   
  8.    AS
  9.    Begin
  10.    SET NOCOUNT ON
  11.     if @Action='xmlImport'
  12.         begin
  13.         declare    @statement varchar(200)
  14.         DECLARE @hDoc int
  15.         DECLARE @error INT 
  16.  
  17.          exec sp_xml_preparedocument @hDoc OUTPUT, @xmldata  
  18.                 set @statement ='Insert Into '+ @table_name    +' '+ 'SELECT * FROM OPENXML('+ convert(varchar, @hDoc) +','+     
  19.                     '''/NewDataSet/Table''' +',2) with '+ @table_name  ;
  20.                   execute (@statement)
  21.          EXEC sp_xml_removedocument @hDoc
  22.           --  end
  23.      end
  24.  
  25.      else if @Action='xmlExport'
  26.             begin 
  27.           set @statement='Select * from '+  @table_name
  28.           execute (@statement)
  29.       end                                                                                      --'+convert(varchar,@hDoc)+ '
  30.   end
  31.  

---------

In @xmldata parameter I m Passing the Path D:\xml\rfid\Branches.xml is it correct or not

Please help me for this
Mar 30 '12 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.