dbTalk Databases Forums  

Openxml - pass parameter

microsoft.public.sqlserver.xml microsoft.public.sqlserver.xml


Discuss Openxml - pass parameter in the microsoft.public.sqlserver.xml forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Newbie
 
Posts: n/a

Default Openxml - pass parameter - 01-10-2004 , 05:39 PM






Hi

I want to open up an xml document from a url and pass it as a
parameter to a stored proc to insert into a db.

<%
Response.Buffer = True
Dim objXMLHTTP, xml, xmlHeadline,oConn, oPath, strSQL

' Create an xmlhttp object:
Set xml = Server.CreateObject("MSXML2.ServerXMLHTTP")

' Opens the connection to the remote server.
xml.Open "POST", "http://somesite.asp?somexml.xml", False
' Actually Sends the request and returns the data:
xml.Send

xmlHeadline = xml.responseXML.xml
' Remove invalid copyright symbol
xmlHeadline= replace(xmlHeadline,chr(169),"")
' Open connection
Set oConn = Server.CreateObject("ADODB.Connection")
oPath="Provider=sqloledb;Data Source=mydatabase;Initial
Catalog=MyCat;Integrated Security=SSPI"
strSQL = "sp_insertHeadlines '" & xmlHeadline & "'"
oConn.open oPath,strSQL
' Check to see if the xml is displayed ok
Response.Write xmlHeadline
Set xml = Nothing
%>

The xml is displayed fine in the browser thanks to response.write, so
its a valid document.

The sp I wrote is:

CREATE PROCEDURE dbo.sp_insertheadlines
(

@xmlHeadline text
)

AS

DECLARE @idoc int

--Create an internal representation of the XML document
EXEC sp_xml_preparedocument @idoc OUTPUT, @xmlHeadline
-- Execute a SELECT statement that uses the OPENXML rowset provider
Insert Into NewsData
SELECT *
FROM OPENXML (@idoc, '/cXmlHeadlineResults/Headline',2)
WITH (
StoryId varchar(80),
StoryUrl varchar(48),
HeadlineText varchar(1000),
BriefText varchar (1000),
ProviderName varchar(200),
ItemTime varchar (50)
)
where StoryId not in (select StoryId from NewsData)
-- Clear the XML document from memory
EXEC sp_xml_removedocument @idoc
GO


This works fine if I set the xml document in the sp, but not if I pass
it as a parameter through asp.

Can someone tell me (slowly!) what I'm doing wrong?!

Thanks

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.