Click to See Complete Forum and Search --> : How to Download http xml feed


emmetmurray
06-23-2008, 09:00 AM
Hi,

Can anyone tell me how to download the data from a xml http feed? Preferably to csv,text, xml file.

I need to get the info from my http xml feed into a sql server database. i have created a mapping scheme for a xml file on my local machine and it works fine, but i need to be able to somehow get the info from my http xml feed into the database, or at least onto a local machine, and i can then run my script.

Any advice would be great.

Thanks

rpgfan3233
06-23-2008, 09:33 AM
You can convert to/from CSV fairly easily as long as you know what the fields would be for the header row, but I would personally stick with XML or use something like highly compressed JSON.

For example, given:
<foo>
<bar example="value"/>
<bar example="value2"/>
</foo>
you might do this in JSON:
{
"foo" : {
"bar" : [
{"@example" : "value"},
{"@example" : "value2"}
]
}
}

Looks like a lot, right? Let's compress it:
{"foo":{"bar":[{"@example":"value"},{"@example":"value2"}]}}

That's a lot smaller than CSV or XML, right? PHP and ASP.NET now have ways of using JSON. In fact, I know PHP has a pair of functions, json_decode (http://php.net/json-decode) and json_encode (http://php.net/json-encode), that use PHP objects (obj->foo->bar[0]->{"@value"}) or even associative arrays (hashes, dictionaries, maps, whatever other name they go by). Be aware that JSON is only a string. You would need to do the json2xml and xml2json functions or find them implemented somewhere already.

I hope this helps!

Edit: If you search this forum, you can find xml2csv and csv2xml discussions if you want to go the CSV route.

emmetmurray
06-23-2008, 10:13 AM
Sorry i have no php knowledge, and wouldn't know where to start with that code you posted.

I just want to import a web xml feed, either directly into a database, of onto my local in some format, so i can then import it using SQLXMLBulkLoad.

Surely there is some asp/vbscript or program that allows you to import a http xml feed into a database.

This is what i've been using so far, but i need to replave "products.xml" with a http url http://www.somesite.com/products.xml

Set objBL = CreateObject("SQLXMLBulkLoad.SQLXMLBulkLoad")
objBL.ConnectionString = "provider=SQLOLEDB.1;data source=IP;database=products;uid=sa;pwd=somepassword"
objBL.ErrorLogFile = "c:\error.log"
objBL.Execute "c:\xml\productmapping.xml", "c:\xml\products.xml"
Set objBL = Nothing

Thanks