Link to home
Start Free TrialLog in
Avatar of John Esraelo
John EsraeloFlag for United States of America

asked on

SQL: Loading XML into a table::

hello team,

A third party of ours offered us a download method for an XML file.
Here is the issue; they are giving us the table in pagination. Meaning, page 1, 2, etc

I suppose, I can loop through x number of pages but don't know how to put them into ONE table and of course ONE xml in sql server 2008
Any assistance is appreciated
ASKER CERTIFIED SOLUTION
Avatar of Mark Wills
Mark Wills
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of John Esraelo

ASKER

It is supposed to be a single table with 10,000 appx records (see URL, softwares.xml).  The keeper of the data does not want to allow users to download the whole table to avoid overload. Therefore, the so called API of theirs is allowing the users to specify a page number.  
http://www.samanage.com/api/index.html
I suppose I can loop thru the X number of pages, insert them as an xml record in a sql table.
At that point I am not sure how to combine all pages together.
Sorry about that... Didn't get back to you in a timely manner...

The hard bit is knowing how many pages. By the looks of things you can specify how many entries per page, not sure if there is a maximum, so would be interesting to first manually explore the maximum.

It does say that every request will give you the number of entries, the number of pages, etc. as part of the header block. While the example says "tickets" the example results seems to be "hardwares".

So, as a strategy I would write an SQL script to get the first 1 entry, examine that for total number of entries, then loop through grabbing a page at a time (saving as a disk file, use the -o param if using curl), specifying the number of entries per page, import that file into a staging table (a temp table would work), then once all pages have been loaded (or no more results), go through the staging table and then put away.  

Not sure why or when you need to combine the pages, assuming what you really want is the resulting nodes.

I would be breaking up the XML into discrete fields / columns based on the nodes of interest to you. You can always recreate an XML document based on those columns depending on what you ultimately want to do (and what format you need).