2013-03-29 18 views
0

我想從xml創建一個查詢。我正在使用xmlparse,但主節點有一個hypen。我不確定如何構建它,以便我可以循環訪問產品。這裏是什麼樣子Coldfusion XMLParse與連字符

http://www.screencast.com/t/GhCgHTymMsR1

我一直在努力做到這一點,但它不工作或者我失去了一些東西。

<cfset result = xmlParse(result.Filecontent)> 
<cfloop index="x" from="1" to="#arrayLen(result["cj-api"]products.product)#"> 

<?xml version="1.0" encoding="UTF-8"?> 
<cj-api> 
    <products total-matched="363" records-returned="2" page-number="1"> 
    <product> 
     <ad-id>10773572</ad-id> 
     <advertiser-id>2955746</advertiser-id> 
     <advertiser-name>Shopko</advertiser-name> 
     <advertiser-category>picture books</advertiser-category> 
     <buy-url>http://www.anrdoezrs.net/click-5917360-10773572?url=http%3A%2F%2Fshopko.com%2Fdetail%2FLEGO-Batman%3A-The-Visual-Book%2F48364%2F0000&amp;cjsku=48364</buy-url> 
    <catalog-id>cjo:398</catalog-id> 
    <currency>USD</currency> 
    <description>Enter the world of your favorite LEGO&amp;#174; super hero in the first ever guide to LEGO&amp;#174; Batman&amp;#8482;! LEGO Batman: The Visual Dictionary combines DK's famous Visual Dictionary format with the adventurous world of the LEGO Caped Crusader.Every set and minifigure from the LEGO Batman universe will now be at your fingertips.</description> 
    <image-url>http://shopko.com/items/shopko/images/small/48364_0000.jpg</image-url> 
    <in-stock></in-stock> 
    <isbn></isbn> 
    <manufacturer-name></manufacturer-name> 
    <manufacturer-sku></manufacturer-sku> 
    <name>LEGO Batman: The Visual Book</name> 
    <price>21.99</price> 
    <retail-price>21.99</retail-price> 
    <sale-price>21.99</sale-price> 
    <sku>48364</sku> 
    <upc></upc> 
</product> 
<product> 
    <ad-id>10773572</ad-id> 
    <advertiser-id>2955746</advertiser-id> 
    <advertiser-name>Shopko</advertiser-name> 
    <advertiser-category>toy figures &amp; playsets</advertiser-category> 
    <buy-url>http://www.jdoqocy.com/click-5917360-10773572?url=http%3A%2F%2Fshopko.com%2Fdetail%2FLEGO-Friends-Olivias-Speedboat%2F59022%2F0000&amp;cjsku=59022</buy-url> 
    <catalog-id>cjo:398</catalog-id> 
    <currency>USD</currency> 
    <description>All aboard for fun in the sun with Olivia's Speedboat!Includes Olivia mini-doll figure Features sand castle, shovel, bucket, beach towel, umbrella and cupBring the LEGO&amp;#174; Friends for a ride around the bay! Build a sand castle or relax in the sun!LEGO Friends pieces are fully compatible with all LEGO System bricks. Collect all of the LEGO Friends sets for a whole city of LEGO Friends fun!LEGO mini-dolls are figures made especially for the world of LEGO Friends, with thousands of customizable fashion and accessory combinations!Measures over 1&amp;#34; (4cm) tall, 4&amp;#34; (10cm) wide and 4&amp;#34; (12cm) long</description> 
    <image-url>http://shopko.com/items/shopko/images/small/59022_0000.jpg</image-url> 
    <in-stock></in-stock> 
    <isbn></isbn> 
    <manufacturer-name></manufacturer-name> 
    <manufacturer-sku></manufacturer-sku> 
    <name>LEGO Friends Olivias Speedboat</name> 
    <price>13.49</price> 
    <retail-price>14.99</retail-price> 
    <sale-price>13.49</sale-price> 
    <sku>59022</sku> 
    <upc></upc> 
    </product> 
    </products> 
</cj-api> 
+0

我要運行,但它可能會幫助別人一)發佈您的代碼B)的錯誤信息以及c)您的CF版本(也有一些輕微的差異) – Leigh

+0

我正在使用cf 9 – Jeff

+0

您是否也可以發佈XML樣本。基本上發佈一個獨立的repro案例,我們可以提出並運行自己。這就是說,您的問題可能只是缺少'.':'結果[「CJ-API」] products.product' –

回答

0

[從評論中提取上述]

你的問題可能只是缺少.。相反的:

result["cj-api"]products.product 

嘗試:

result["cj-api"].products.product 
+0

謝謝你的幫助! – Jeff