RE: XML! Aaargh! How do I do this?
Hopefully, the error of my ways will be obvious to thos of you who work with xml a lot, but...HELP!!! Given this demo xml: ?xml version=1.0? Products Category ID=1Air Conditioners/Category SubCategory ID=1 SubCategoryNameAir Conditioners/SubCategoryName ShortDescription/ LongDescription/ Product ID=XC21 New=N EnergyStar=Y SortOrder=100 ModelNumberXC21/ModelNumber ModelNameXC21 Air Conditioner/ModelName OneLinerThe most quiet and efficient central air conditioner you can buy/OneLiner Ratings Rating Type=SEERup to 20.5/Rating Rating Type=Sound69/Rating /Ratings SmallImagehttp://www.lennox.com/res/photos/44383_small.jpg/SmallImage PriceGuide$$$/PriceGuide /Product (product repeats ...) What's wrong with this code? I constantly get the error: The value coldfusion.xml.XmlNodeList cannot be converted to a number. The error occurred on line 44, which reads: cfset arrResult = xmlSearch(xmllennox-products,xp) Suggests, good tutorials? The one I've been following isn't quite complete enough the complexity of my xml sheet. Rick html head titleLennox XML Search Test/title /head body h1xmlSearch()/h1 cfset xmlLennox = xmlParse(expandPath('lennox-products.xml')) cfoutput table border='1' cellpadding='2' cellspacing='0' tr thXPath/th thResult/th /tr cfset arrXPs = arrayNew(1) cfset arrayAppend(arrXPs,'/products') cfset arrayAppend(arrXPs,'/products/category') cfset arrayAppend(arrXPs,'/products/category/subCategory') cfset arrayAppend(arrXPs,'/products/category/subCategory/subCategoryName') cfset arrayAppend(arrXPs,'/products/category/subCategory/shortDescription') cfset arrayAppend(arrXPs,'/products/category/subCategory/longDescription') cfset arrayAppend(arrXPs,'/products/category/subCategory/product/') cfset arrayAppend(arrXPs,'/products/category/subCategory/product/modelNumber') cfset arrayAppend(arrXPs,'/produtts/category/subCategory/product/modelName') cfset arrayAppend(arrXPs,'/products/category/subCategory/product/modelName/text()' ) cfset arrayAppend(arrXPs,'/products/category/subCategory/product/oneLiner') cfset arrayAppend(arrXPs,'/products/category/subCategory/product/ratings') cfset arrayAppend(arrXPs,'/products/category/subCategory/product/smallImage') cfset arrayAppend(arrXPs,'/products/category/subCategory/product/priceGuide') cfloop index='index' from='1' to='#arrayLen(arrXPs)#' cfset xp = arrXPs[index] cfset arrResult = xmlSearch(xmllennox-products,xp) tr valign='top' td#xp#/td td ul cfloop index='index' from='1' to='#arrayLen(arrResult)#' li#xmlGetNodeType(arrResult[index])#: cftry #arrResult[index].xmlText# cfcatch type='any'#arrResult[index]#/cfcatch /cftry /li /cfloop /ul /td /tr /cfloop /table /cfoutput /body /html -Original Message- From: James Holmes [mailto:james.hol...@gmail.com] Sent: Friday, December 30, 2011 8:14 PM To: cf-talk Subject: Re: XML! Aaargh! How do I do this? If you are just after products, you can dramatically simplify the code by using xmlsearch() to get them with xpath instead of manually looping multiple levels down. -- Shu Ha Ri: Agile and .NET blog http://www.bifrost.com.au/ On 31 December 2011 08:50, Justin Scott leviat...@darktech.org wrote: Okay... I've worked this every way I can think of and, I admit it, I just don't get it. Hi Rick, replace your inner-most loop with the following. It should get you going in the right direction. It looks like there is another layer of sub
Re: XML! Aaargh! How do I do this?
Rick, I generally find the easiest way to work through an XML doc is to create a page that just converts it to an XMLDOC first using cfxml or xmlparse() and them CFDUMP the result. This makes it must easier to find the node references you need to loop through or reference. I also prefer to simplify my code by creating a new reference out deep nested blocks, such as nodes I need to loop over, as this results in shorter references, especially if they contains array counters, dynamic evaluations etc to get at the correct element. If your still struggling, then I would suggest posting the full code and XML at pastebin.com so we can see it and test it. -- Russ Michaels www.bluethunderinternet.com : Business hosting services solutions www.cfmldeveloper.com: ColdFusion developer community www.michaels.me.uk : my blog www.cfsearch.com : ColdFusion search engine ** *skype me* : russmichaels ~| Order the Adobe Coldfusion Anthology now! http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:349285 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm
RE: XML! Aaargh! How do I do this?
What are the values of xmllennox in the xml page (or what is it supposed to be derived from)? And what is the search trying to search for? -Original Message- From: Rick Faircloth [mailto:r...@whitestonemedia.com] Sent: Sunday, January 01, 2012 3:53 PM To: cf-talk Subject: RE: XML! Aaargh! How do I do this? Hopefully, the error of my ways will be obvious to thos of you who work with xml a lot, but...HELP!!! Given this demo xml: ?xml version=1.0? Products Category ID=1Air Conditioners/Category SubCategory ID=1 SubCategoryNameAir Conditioners/SubCategoryName ShortDescription/ LongDescription/ Product ID=XC21 New=N EnergyStar=Y SortOrder=100 ModelNumberXC21/ModelNumber ModelNameXC21 Air Conditioner/ModelName OneLinerThe most quiet and efficient central air conditioner you can buy/OneLiner Ratings Rating Type=SEERup to 20.5/Rating Rating Type=Sound69/Rating /Ratings SmallImagehttp://www.lennox.com/res/photos/44383_small.jpg/SmallImage PriceGuide$$$/PriceGuide /Product (product repeats ...) What's wrong with this code? I constantly get the error: The value coldfusion.xml.XmlNodeList cannot be converted to a number. The error occurred on line 44, which reads: cfset arrResult = xmlSearch(xmllennox-products,xp) Suggests, good tutorials? The one I've been following isn't quite complete enough the complexity of my xml sheet. Rick html head titleLennox XML Search Test/title /head body h1xmlSearch()/h1 cfset xmlLennox = xmlParse(expandPath('lennox-products.xml')) cfoutput table border='1' cellpadding='2' cellspacing='0' tr thXPath/th thResult/th /tr cfset arrXPs = arrayNew(1) cfset arrayAppend(arrXPs,'/products') cfset arrayAppend(arrXPs,'/products/category') cfset arrayAppend(arrXPs,'/products/category/subCategory') cfset arrayAppend(arrXPs,'/products/category/subCategory/subCategoryName') cfset arrayAppend(arrXPs,'/products/category/subCategory/shortDescription') cfset arrayAppend(arrXPs,'/products/category/subCategory/longDescription') cfset arrayAppend(arrXPs,'/products/category/subCategory/product/') cfset arrayAppend(arrXPs,'/products/category/subCategory/product/modelNumber') cfset arrayAppend(arrXPs,'/produtts/category/subCategory/product/modelName') cfset arrayAppend(arrXPs,'/products/category/subCategory/product/modelName/text()' ) cfset arrayAppend(arrXPs,'/products/category/subCategory/product/oneLiner') cfset arrayAppend(arrXPs,'/products/category/subCategory/product/ratings') cfset arrayAppend(arrXPs,'/products/category/subCategory/product/smallImage') cfset arrayAppend(arrXPs,'/products/category/subCategory/product/priceGuide') cfloop index='index' from='1' to='#arrayLen(arrXPs)#' cfset xp = arrXPs[index] cfset arrResult = xmlSearch(xmllennox-products,xp) tr valign='top' td#xp#/td td ul cfloop index='index' from='1' to='#arrayLen(arrResult)#' li#xmlGetNodeType(arrResult[index])#: cftry #arrResult[index].xmlText# cfcatch type='any'#arrResult[index]#/cfcatch /cftry /li /cfloop /ul /td /tr /cfloop /table /cfoutput /body /html -Original Message- From: James Holmes [mailto:james.hol...@gmail.com] Sent: Friday, December 30, 2011 8:14 PM To: cf-talk Subject: Re: XML! Aaargh! How do I do this? If you are just after products, you can dramatically simplify the code by using xmlsearch() to get them with xpath instead of manually looping multiple levels down. -- Shu Ha Ri: Agile and .NET blog http://www.bifrost.com.au
RE: XML! Aaargh! How do I do this?
Sorry, guys... complete forgot to post the CF code! At this point, all I'm really after is the modelName/text() (See below)... I just haven't gotten to the point where I understand how to parse through the node and info, therein. If you need more code, I'll go to pastbin. Thanks for the feedback! Rick html head titleLennox XML Search Test/title /head body h1xmlSearch()/h1 cfset xmlLennox = xmlParse(expandPath('lennox-products.xml')) cfoutput table border='1' cellpadding='2' cellspacing='0' tr thXPath/th thResult/th /tr cfset arrXPs = arrayNew(1) cfset arrayAppend(arrXPs,'/products') cfset arrayAppend(arrXPs,'/products/category') cfset arrayAppend(arrXPs,'/products/category/subCategory') cfset arrayAppend(arrXPs,'/products/category/subCategory/subCategoryName') cfset arrayAppend(arrXPs,'/products/category/subCategory/shortDescription') cfset arrayAppend(arrXPs,'/products/category/subCategory/longDescription') cfset arrayAppend(arrXPs,'/products/category/subCategory/product/') cfset arrayAppend(arrXPs,'/products/category/subCategory/product/modelNumber') cfset arrayAppend(arrXPs,'/produtts/category/subCategory/product/modelName') cfset arrayAppend(arrXPs,'/products/category/subCategory/product/modelName/text()' ) cfset arrayAppend(arrXPs,'/products/category/subCategory/product/oneLiner') cfset arrayAppend(arrXPs,'/products/category/subCategory/product/ratings') cfset arrayAppend(arrXPs,'/products/category/subCategory/product/smallImage') cfset arrayAppend(arrXPs,'/products/category/subCategory/product/priceGuide') cfloop index='index' from='1' to='#arrayLen(arrXPs)#' cfset xp = arrXPs[index] cfset arrResult = xmlSearch(xmllennox-products,xp) tr valign='top' td#xp#/td td ul cfloop index='index' from='1' to='#arrayLen(arrResult)#' li#xmlGetNodeType(arrResult[index])#: cftry #arrResult[index].xmlText# cfcatch type='any'#arrResult[index]#/cfcatch /cftry /li /cfloop /ul /td /tr /cfloop /table /cfoutput /body /html -Original Message- From: Eric Roberts [mailto:ow...@threeravensconsulting.com] Sent: Sunday, January 01, 2012 6:32 PM To: cf-talk Subject: RE: XML! Aaargh! How do I do this? What are the values of xmllennox in the xml page (or what is it supposed to be derived from)? And what is the search trying to search for? -Original Message- From: Rick Faircloth [mailto:r...@whitestonemedia.com] Sent: Sunday, January 01, 2012 3:53 PM To: cf-talk Subject: RE: XML! Aaargh! How do I do this? Hopefully, the error of my ways will be obvious to thos of you who work with xml a lot, but...HELP!!! Given this demo xml: ?xml version=1.0? Products Category ID=1Air Conditioners/Category SubCategory ID=1 SubCategoryNameAir Conditioners/SubCategoryName ShortDescription/ LongDescription/ Product ID=XC21 New=N EnergyStar=Y SortOrder=100 ModelNumberXC21/ModelNumber ModelNameXC21 Air Conditioner/ModelName OneLinerThe most quiet and efficient central air conditioner you can buy/OneLiner Ratings Rating Type=SEERup to 20.5/Rating Rating Type=Sound69/Rating /Ratings SmallImagehttp://www.lennox.com/res/photos/44383_small.jpg/SmallImage PriceGuide$$$/PriceGuide /Product (product repeats ...) What's wrong with this code? I constantly get the error: The value coldfusion.xml.XmlNodeList cannot be converted to a number. The error occurred on line 44, which reads: cfset arrResult = xmlSearch(xmllennox-products,xp) Suggests, good tutorials? The one I've been following isn't quite complete enough the complexity of my xml sheet
Re: XML! Aaargh! How do I do this?
Try searching directly for the modelName: cfset result = xmlSearch(xmllennox-products,//modelName) Dump that result to see how to get the name. -- Shu Ha Ri: Agile and .NET blog http://www.bifrost.com.au/ On 2 January 2012 09:18, Rick Faircloth r...@whitestonemedia.com wrote: At this point, all I'm really after is the modelName/text() ~| Order the Adobe Coldfusion Anthology now! http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:349288 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm
Re: XML! Aaargh! How do I do this?
BTW, the issue with the existing code is this: xmllennox-products CF thinks you are trying to do maths on xmllennox and products by subtracting one from the other. -- Shu Ha Ri: Agile and .NET blog http://www.bifrost.com.au/ On 2 January 2012 10:10, James Holmes james.hol...@gmail.com wrote: xmllennox-products ~| Order the Adobe Coldfusion Anthology now! http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:349289 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm
Re: XML! Aaargh! How do I do this?
Okay... I've worked this every way I can think of and, I admit it, I just don't get it. Hi Rick, replace your inner-most loop with the following. It should get you going in the right direction. It looks like there is another layer of sub-categories which needs to be accounted for: !--- Loop over the sub-categories --- cfloop from='1' to='#arrayLen(xmlProductContent.products.SubCategory)#' index='subCategoryCount' !--- Localize our current sub-category --- cfset thisSubCategory = xmlProductContent.products.SubCategory[subCategoryCount] / h2#thisSubCategory.SubCategoryName.xmlText#/h2 !--- Loop over the products in this sub-category --- cfloop from=1 to=#arrayLen(thisSubCategory.Product)# index=productCount !--- Localize our current product for easier access --- cfset thisProduct = thisSubCategory.Product[productCount] / !---cfdump var=#thisProduct# /--- p ID: #thisProduct.xmlAttributes.ID#br / Model Name: #thisProduct.ModelName.xmlText#br / Image: img src=#thisProduct.SmallImage.xmlText# / /p /cfloop !--- Products --- /cfloop !--- Sub-Categories --- -Justin Scott ~| Order the Adobe Coldfusion Anthology now! http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:349274 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm
Re: XML! Aaargh! How do I do this?
If you are just after products, you can dramatically simplify the code by using xmlsearch() to get them with xpath instead of manually looping multiple levels down. -- Shu Ha Ri: Agile and .NET blog http://www.bifrost.com.au/ On 31 December 2011 08:50, Justin Scott leviat...@darktech.org wrote: Okay... I've worked this every way I can think of and, I admit it, I just don't get it. Hi Rick, replace your inner-most loop with the following. It should get you going in the right direction. It looks like there is another layer of sub-categories which needs to be accounted for: !--- Loop over the sub-categories --- cfloop from='1' to='#arrayLen(xmlProductContent.products.SubCategory)#' index='subCategoryCount' !--- Localize our current sub-category --- cfset thisSubCategory = xmlProductContent.products.SubCategory[subCategoryCount] / h2#thisSubCategory.SubCategoryName.xmlText#/h2 !--- Loop over the products in this sub-category --- cfloop from=1 to=#arrayLen(thisSubCategory.Product)# index=productCount !--- Localize our current product for easier access --- cfset thisProduct = thisSubCategory.Product[productCount] / !---cfdump var=#thisProduct# /--- p ID: #thisProduct.xmlAttributes.ID#br / Model Name: #thisProduct.ModelName.xmlText#br / Image: img src=#thisProduct.SmallImage.xmlText# / /p /cfloop !--- Products --- /cfloop !--- Sub-Categories --- -Justin Scott ~| Order the Adobe Coldfusion Anthology now! http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:349275 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm
RE: XML! Aaargh! How do I do this?
Thanks for the tip, Justin! I'll give it a try! Rick -Original Message- From: Justin Scott [mailto:leviat...@darktech.org] Sent: Friday, December 30, 2011 7:51 PM To: cf-talk Subject: Re: XML! Aaargh! How do I do this? Okay... I've worked this every way I can think of and, I admit it, I just don't get it. Hi Rick, replace your inner-most loop with the following. It should get you going in the right direction. It looks like there is another layer of sub-categories which needs to be accounted for: !--- Loop over the sub-categories --- cfloop from='1' to='#arrayLen(xmlProductContent.products.SubCategory)#' index='subCategoryCount' !--- Localize our current sub-category --- cfset thisSubCategory = xmlProductContent.products.SubCategory[subCategoryCount] / h2#thisSubCategory.SubCategoryName.xmlText#/h2 !--- Loop over the products in this sub-category --- cfloop from=1 to=#arrayLen(thisSubCategory.Product)# index=productCount !--- Localize our current product for easier access --- cfset thisProduct = thisSubCategory.Product[productCount] / !---cfdump var=#thisProduct# /--- p ID: #thisProduct.xmlAttributes.ID#br / Model Name: #thisProduct.ModelName.xmlText#br / Image: img src=#thisProduct.SmallImage.xmlText# / /p /cfloop !--- Products --- /cfloop !--- Sub-Categories --- -Justin Scott ~| Order the Adobe Coldfusion Anthology now! http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:349276 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm
RE: XML! Aaargh! How do I do this?
Thanks for the info, James! I had actually been doing some more research on CF and XML and was reading about xmlSearch. I'll give that try, too. Rick -Original Message- From: James Holmes [mailto:james.hol...@gmail.com] Sent: Friday, December 30, 2011 8:14 PM To: cf-talk Subject: Re: XML! Aaargh! How do I do this? If you are just after products, you can dramatically simplify the code by using xmlsearch() to get them with xpath instead of manually looping multiple levels down. -- Shu Ha Ri: Agile and .NET blog http://www.bifrost.com.au/ On 31 December 2011 08:50, Justin Scott leviat...@darktech.org wrote: Okay... I've worked this every way I can think of and, I admit it, I just don't get it. Hi Rick, replace your inner-most loop with the following. It should get you going in the right direction. It looks like there is another layer of sub-categories which needs to be accounted for: !--- Loop over the sub-categories --- cfloop from='1' to='#arrayLen(xmlProductContent.products.SubCategory)#' index='subCategoryCount' !--- Localize our current sub-category --- cfset thisSubCategory = xmlProductContent.products.SubCategory[subCategoryCount] / h2#thisSubCategory.SubCategoryName.xmlText#/h2 !--- Loop over the products in this sub-category --- cfloop from=1 to=#arrayLen(thisSubCategory.Product)# index=productCount !--- Localize our current product for easier access --- cfset thisProduct = thisSubCategory.Product[productCount] / !---cfdump var=#thisProduct# /--- p ID: #thisProduct.xmlAttributes.ID#br / Model Name: #thisProduct.ModelName.xmlText#br / Image: img src=#thisProduct.SmallImage.xmlText# / /p /cfloop !--- Products --- /cfloop !--- Sub-Categories --- -Justin Scott ~| Order the Adobe Coldfusion Anthology now! http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:349277 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm