?
Solved

import XML data into SQL table via Stored Procedure

Posted on 2010-01-12
7
Medium Priority
?
593 Views
Last Modified: 2012-08-13
I need to write a stored procedure that will import data from a dynamic XML feed into my sql table
the xml feed would be something like
http://www.zillow.com/webservice/GetSearchResults.htm?zws-id=X1-ZWz1cwo6lcszyj_aui2x&address=12598+Dupont+Drive&citystatezip=Rancho+Cucamonga+91739
with the address being dynamic
i.e. http://www.zillow.com/webservice/GetSearchResults.htm?zws-id=X1-ZWz1cwo6lcszyj_aui2x&address=" + address + "&citystatezip=" + city + "+" + zip

I have tried
select * from OpenRowSet(BULK N'LinkGoesHere') as test
with no success.

I basically want to grab one field sestimate from the xml file and import it into a table called properties that has a field with the same name

any suggestions?
0
Comment
Question by:bob1barker
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 19

Expert Comment

by:elimesika
ID: 26294620
HI

you have to do that dynamically.
DECLARE @xml XML, @sql nvarchar(1000), @ParameterList nvarchar(100)
			 SET @ParameterList = '@xml xml OUTPUT'

			set @sql = 'select * from OpenRowSet(BULK N''' + LinkGoesHere + ''') as test'

			--Convert file content to a xml variable
			EXECUTE sp_executesql @sql, @ParameterList, @xml = @xml OUTPUT

Open in new window

0
 
LVL 19

Accepted Solution

by:
elimesika earned 2000 total points
ID: 26294682
Then, you use this to insert the value to  yourtable.yourfield
INSERT yourtable (yourfield) (
				SELECT  t.c.[value](''@yourxmlattributename'',''nvarchar(100)'') as [Value]
				FROM @xml.nodes(''XPATH expression to your value'')as t(c))

Open in new window

0
 

Author Comment

by:bob1barker
ID: 26294713
when I try that I get the following error
Operating system error code 123(The filename, directory name, or volume label syntax is incorrect.).


DECLARE @Link nvarchar(1000), @xml XML, @sql nvarchar(1000), @ParameterList nvarchar(100)
                         SET @ParameterList = '@xml xml OUTPUT'
 set @link = 'http://www.zillow.com/webservice/GetSearchResults.htm?zws-id=X1-ZWz1cwo6lcszyj_aui2x&address=12598+Dupont+Drive&citystatezip=Rancho+Cucamonga+91739'
                        set @sql = 'select * from OpenRowSet(BULK N''' + @Link + ''', Single_Blob) as test'
 
                        --Convert file content to a xml variable
                        EXECUTE sp_executesql @sql, @ParameterList, @xml = @xml OUTPUT
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 19

Expert Comment

by:elimesika
ID: 26294763
Try to add a standard xml header to your XML

<?xml version="1.0" encoding="utf-8" ?>

Open in new window

0
 

Author Comment

by:bob1barker
ID: 26294778
its in the file already
click that link and you should see it
<?xml version="1.0" encoding="utf-8" ?>

its also from another source so I dont have any control over the file
0
 
LVL 19

Expert Comment

by:elimesika
ID: 26294845
Try first to copy the xml to your machine and get to it by file:// instead of http:// 
We have to check that syntax is OK
0
 

Author Comment

by:bob1barker
ID: 26295053
works perfect from my local machine
weird
0

Featured Post

Tutorials alone can't teach real engineering

So we built better training tools.

-Hands-on Labs
-Instructor Mentoring
-Scenario-Based Tests
-Dedicated Cloud Servers

All at your fingertips. What are you waiting for?

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question