XMl Import

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • satishv96
    New Member
    • Feb 2012
    • 2

    XMl Import

    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_xmlbulkinser t] ( @xmldata = D:\xml\rfid\Bra nches.xml, @table_name = Branches, @Action = xmlImport ).

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

    And my SP is



    Code:
    set ANSI_NULLS ON
    set QUOTED_IDENTIFIER ON
    GO
      ALTER PROC [dbo].[sp_xmlbulkinsert] 
       @xmldata varchar(max) =null,
       @table_name varchar(50),
       @Action varchar(50)   
       AS
       Begin
       SET NOCOUNT ON
        if @Action='xmlImport'
    		begin
    		declare	@statement varchar(200)
    		DECLARE @hDoc int
    		DECLARE @error INT 
    
    		 exec sp_xml_preparedocument @hDoc OUTPUT, @xmldata  
    		        set @statement ='Insert Into '+ @table_name	+' '+ 'SELECT * FROM OPENXML('+ convert(varchar, @hDoc) +','+     
    					'''/NewDataSet/Table''' +',2) with '+ @table_name  ;
    		          execute (@statement)
    		 EXEC sp_xml_removedocument @hDoc
              --  end
         end
    
    	 else if @Action='xmlExport'
    			begin 
              set @statement='Select * from '+  @table_name
    		  execute (@statement)
          end                                                                                      --'+convert(varchar,@hDoc)+ '
      end

    ---------

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

    Please help me for this
    Last edited by PsychoCoder; Mar 30 '12, 07:19 AM. Reason: Code tags added
Working...