开发者

Display XML data with classic ASP

Morning All,

I am struggling to get this code to work. I have spent hours tuning, altering it.. and it still wont work.

<%
Dim nTitle, nDescription, nWeight, nImage, nPrice, StoreMemberID, nDobaID, StoreItemCatID, nTrue, nFalse, MarkupPerc, nYes, nNo
Dim nFileName, intNewID, paryProducts

FUNCTION FetchProductRecords(str)

  Dim objHTTP, RSSURL, RSSFeed, xmlRSSFeed, RSSItems, objItem, objChild, paryOut, nCell
  Redim paryOut(6,-1)
  nCell = 0
  RSSURL = "http://www.storeboard.com/excel/" & str

  Set objHTTP = Server.CreateObject("Msxml2.ServerXMLHTTP")
  objHTTP.open "GET",RSSURL,false
  objHTTP.send
  RSSFeed = objHTTP.responseText

  Set xmlRSSFeed = Server.CreateObject("MSXML2.DomDocument")
  xmlRSSFeed.async = false
  xmlRSSFeed.LoadXml(RSSFeed)
  Set objHTTP = Noth开发者_StackOverflow中文版ing

  Set RSSItems = xmlRSSFeed.getElementsByTagName("Row")
  Set xmlRSSFeed = Nothing

  Redim preserve paryOut(6,RSSItems.length-1)
  FOR i = 0 TO RSSItems.length - 1
    Set RSSItem = RSSItems.Item(i)
    FOR EACH objChild IN RSSItem.childNodes
      IF nCell = 3 THEN
        paryOut(0,i) = objChild.text
      ELSEIF nCell = 5 THEN
        paryOut(1,i) = objChild.text
      ELSEIF nCell = 7 THEN
        paryOut(2,i) = objChild.text
      ELSEIF nCell = 27 THEN
        paryOut(3,i) = objChild.text
      ELSEIF nCell = 23 THEN
        paryOut(4,i) = objChild.text
      ELSEIF nCell = 40 THEN
        paryOut(5,i) = objChild.text
      END IF
      nCell = nCell + 1
    NEXT
    nCell = 0
  NEXT
  FetchProductRecords = paryOut
END FUNCTION

paryProducts = FetchProductRecords(nFileName)
IF isArray(paryProducts) THEN
%>
<table cellpadding="0" cellspacing="0" border="1" width="100%">
  <tr style="background-color:#000000;color:#FFFFFF;font-weight:bold;font-family:Arial, Helvetica, sans-serif;font-size:10px">
    <td style="padding:5px" align="center">DOBA ID</td>
    <td style="padding:5px" align="center">TITLE</td>
    <td style="padding:5px" align="center">DESCRIPTION</td>
    <td style="padding:5px" align="center">PRICE</td>
    <td style="padding:5px" align="center">WEIGHT</td>
    <td style="padding:5px" align="center">IMAGE</td>
  </tr>
  <% FOR i = 0 TO uBound(paryProducts,2) %>
  <% IF i > 0 THEN ' to avoid the header %>
  <tr style="font-family:Arial, Helvetica, sans-serif;font-size:10px">
    <td style="padding:5px"><%=paryProducts(0,i)%></td>
    <td style="padding:5px"><%=paryProducts(1,i)%></td>
    <td style="padding:5px"><%=paryProducts(2,i)%></td>
    <td style="padding:5px"><%=paryProducts(3,i)%></td>
    <td style="padding:5px"><%=paryProducts(4,i)%></td>
    <td style="padding:5px"><%=paryProducts(5,i)%></td>
  </tr>
  <% END IF %>
  <% NEXT %>
</table>
<% END IF %>

All in all the XML file have 40 something fields. You can check out the xml file here: http://www.storeboard.com/excel/cameras2.xml

I would appreciate any assistance with this code so I can finally finish it off.

Have a great day and a Merry Christmas, Paul


You do have set the nFileName to be "cameras2.xml", right ?

nFileName = "cameras2.xml"
paryProducts = FetchProductRecords(nFileName)

Other than that, it works great from my machine..

If your application and XML reside on the same site then check out this article INFO: Do Not Send ServerXMLHTTP or WinHTTP Requests to the Same Server


@neojakey: The problem I see is that the number of cells in each row don't match. In the first row (the 'header'), there are 45 cells. Each subsequent row has less cells, but never up to 45 and they don't appear to correlate either. I've lined up the second row's data with the first row to show you what I mean:

+----+------------------------+-------------------------------------------------------------------------------------------------------+
|  0 | supplier_id            | 4                                                                                                     |
+----+------------------------+-------------------------------------------------------------------------------------------------------+
|  1 | drop_ship_fee          | 0                                                                                                     |
+----+------------------------+-------------------------------------------------------------------------------------------------------+
|  2 | supplier_name          | Diamond                                                                                               |
+----+------------------------+-------------------------------------------------------------------------------------------------------+
|  3 | product_id             | 17697                                                                                                 |
+----+------------------------+-------------------------------------------------------------------------------------------------------+
|  4 | product_sku            | BCR10                                                                                                 |
+----+------------------------+-------------------------------------------------------------------------------------------------------+
|  5 | title                  | OmniSource 10 12 AC/DC Charger                                                                        |
+----+------------------------+-------------------------------------------------------------------------------------------------------+
|  6 | warranty               | OmniSource 10 12 AC/DC Charger / Reconditioner for VHS &amp; VHS-C (9.6V to 12V) full size camcorders |
+----+------------------------+-------------------------------------------------------------------------------------------------------+
|  7 | description            | new                                                                                                   |
+----+------------------------+-------------------------------------------------------------------------------------------------------+
|  8 | condition              | Lenmar                                                                                                |
+----+------------------------+-------------------------------------------------------------------------------------------------------+
|  9 | details                | 0                                                                                                     |
+----+------------------------+-------------------------------------------------------------------------------------------------------+
| 10 | manufacturer           | 2010-12-19T17:24:23.000                                                                               |
+----+------------------------+-------------------------------------------------------------------------------------------------------+
| 11 | brand_name             | 22091                                                                                                 |
+----+------------------------+-------------------------------------------------------------------------------------------------------+
| 12 | case_pack_quantity     | BCR10                                                                                                 |
+----+------------------------+-------------------------------------------------------------------------------------------------------+
| 13 | country_of_origin      | 2147483647                                                                                            |
+----+------------------------+-------------------------------------------------------------------------------------------------------+
| 14 | product_last_update    | 2147483647                                                                                            |
+----+------------------------+-------------------------------------------------------------------------------------------------------+
| 15 | item_id                | OmniSource 10 12 AC/DC Charger                                                                        |
+----+------------------------+-------------------------------------------------------------------------------------------------------+
| 16 | item_sku               | 0                                                                                                     |
+----+------------------------+-------------------------------------------------------------------------------------------------------+
| 17 | mpn                    | 0                                                                                                     |
+----+------------------------+-------------------------------------------------------------------------------------------------------+
| 18 | upc                    | 1.95                                                                                                  |
+----+------------------------+-------------------------------------------------------------------------------------------------------+
| 19 | item_name              | 8.27                                                                                                  |
+----+------------------------+-------------------------------------------------------------------------------------------------------+
| 20 | item_weight            | 28.01                                                                                                 |
+----+------------------------+-------------------------------------------------------------------------------------------------------+
| 21 | ship_alone             | 27.2                                                                                                  |
+----+------------------------+-------------------------------------------------------------------------------------------------------+
| 22 | ship_freight           | 69.95                                                                                                 |
+----+------------------------+-------------------------------------------------------------------------------------------------------+
| 23 | ship_weight            | 4                                                                                                     |
+----+------------------------+-------------------------------------------------------------------------------------------------------+
| 24 | ship_cost              | in-stock                                                                                              |
+----+------------------------+-------------------------------------------------------------------------------------------------------+
| 25 | max_ship_single_box    | 0                                                                                                     |
+----+------------------------+-------------------------------------------------------------------------------------------------------+
| 26 | map                    | 2010-12-16T15:06:25.000                                                                               |
+----+------------------------+-------------------------------------------------------------------------------------------------------+
| 27 | price                  | Catalog||Electronics &amp; computer||Camera &amp; photo||Digital camera accessories                   |
+----+------------------------+-------------------------------------------------------------------------------------------------------+
| 28 | custom_price           | http://images.doba.com/products/4/images_prodLarge_BCR10.jpg                                          |
+----+------------------------+-------------------------------------------------------------------------------------------------------+
| 29 | prepay_price           | 400                                                                                                   |
+----+------------------------+-------------------------------------------------------------------------------------------------------+
| 30 | street_price           | 400                                                                                                   |
+----+------------------------+-------------------------------------------------------------------------------------------------------+
| 31 | msrp                   | 0                                                                                                     |
+----+------------------------+-------------------------------------------------------------------------------------------------------+
| 32 | qty_avail              |                                                                                                       |
+----+------------------------+-------------------------------------------------------------------------------------------------------+
| 33 | stock                  |                                                                                                       |
+----+------------------------+-------------------------------------------------------------------------------------------------------+
| 34 | est_avail              |                                                                                                       |
+----+------------------------+-------------------------------------------------------------------------------------------------------+
| 35 | qty_on_order           |                                                                                                       |
+----+------------------------+-------------------------------------------------------------------------------------------------------+
| 36 | item_last_update       |                                                                                                       |
+----+------------------------+-------------------------------------------------------------------------------------------------------+
| 37 | item_discontinued_date |                                                                                                       |
+----+------------------------+-------------------------------------------------------------------------------------------------------+
| 38 | categories             |                                                                                                       |
+----+------------------------+-------------------------------------------------------------------------------------------------------+
| 39 | attributes             |                                                                                                       |
+----+------------------------+-------------------------------------------------------------------------------------------------------+
| 40 | image_file             |                                                                                                       |
+----+------------------------+-------------------------------------------------------------------------------------------------------+
| 41 | image_width            |                                                                                                       |
+----+------------------------+-------------------------------------------------------------------------------------------------------+
| 42 | image_height           |                                                                                                       |
+----+------------------------+-------------------------------------------------------------------------------------------------------+
| 43 | additional_images      |                                                                                                       |
+----+------------------------+-------------------------------------------------------------------------------------------------------+
| 44 | is_customized          |                                                                                                       |
+----+------------------------+-------------------------------------------------------------------------------------------------------+

Since the product_id never moves from #3 and title never moves from #5, your application appeared to be working. However, the description, price, weight and image fields are broken due to the data mismatching. If you update the code where you loop through RSSItem.childNodes to

IF nCell = 3 THEN
    paryOut(0,i) = objChild.text 'product_id'
ELSEIF nCell = 5 THEN
    paryOut(1,i) = objChild.text 'title'
ELSEIF nCell = 6 THEN
    paryOut(2,i) = objChild.text 'description'
ELSEIF nCell = 27 THEN
    paryOut(3,i) = objChild.text 'price - could be ?'
ELSEIF nCell = 23 THEN
    paryOut(4,i) = objChild.text 'weight - could be ?'
ELSEIF nCell = 28 THEN
    paryOut(5,i) = objChild.text 'image'
END IF

...this issue will be fixed for many of your products and you'll at least get the right description instead of the product's condition, as well as the image_file more often than never getting it at all.

The solution to the problem however is to get what ever is generating the data in the first place to produce <Cell>0</Cell> if it can't find a value for the header cell it is supposed to display instead of just not outputting it at all which is messing up with your application's hard-coded logic.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜