I have this regex code that used to work in CF10 but since moving to Lucee,
it no longer works. (The problem is not Lucee, it is the Regex, and Lucee
just seems to be less forgiving…)
The code is:
<cfset ThisNode =
#XMLSearch(xmlResponse,“//[local-name()=‘price_quotes’]/[local-name()=‘price_quote’]
[* = ‘#CanPost_ServiceRegion##xmldata.CanPost_service_code#’
]/count(preceding-sibling::) + 1")#>
The variable in the middle could be USA.SP.AIR for the purpuse of testing:
so
<cfset ThisNode =
#XMLSearch(xmlResponse,"//[local-name()=‘price_quotes’]/[local-name()=‘price_quote’]
[ = ‘USA.SP.AIR’ ]/count(preceding-sibling::*) + 1”)#>
The closes I get to something right is:
count(preceding-sibling:://[local-name()=‘price_quotes’]/[local-name()=‘price_quote’]
[* = ‘USA.SP.AIR’ ]) + 1
But it always returns 1, instead of the actual position +1…
Can someone point me in the right direction?
The test xml file could be:
<?xml version="1.0" encoding="UTF_8"?> http://www.canadapost.ca/ws/ship/rate_v2"><price_quote><service_code>USA.EP</service_code><service_link
rel=“service” href="
https://soa_gw.canadapost.ca:443/rs/ship/service/USA.EP?contract=
https://soa_gw.canadapost.ca/rs/ship/service/USA.EP?contract=0040024030&country=US
004002000
https://soa_gw.canadapost.ca/rs/ship/service/USA.XP?contract=0040024030&country=US&country=US"
media_type=“application/vnd.cpc.ship.rate_v2+xml”/><service_name>Expedited
Parcel
USA</service_name><price_details>19.400.000.000.0020.22<option_code>DC</option_code><option_name>Delivery
confirmation</option_name><option_price>0</option_price><adjustment_code>FUELSC</adjustment_code><adjustment_name>Fuel
surcharge</adjustment_name><adjustment_cost>0.82</adjustment_cost>4.25</price_details><weight_details/><service_standard><am_delivery>false</am_delivery><guaranteed_delivery>false</guaranteed_delivery><expected_transit_time>4</expected_transit_time><expected_delivery_date>2015_11_19</expected_delivery_date></service_standard></price_quote><price_quote><service_code>USA.PW.PAK</service_code><service_link
rel=“service” href="
https://soa_gw.canadapost.ca:443/rs/ship/service/USA.PW.PAK?contract=
https://soa_gw.canadapost.ca/rs/ship/service/USA.PW.PAK?contract=0040024030&country=US
004002000
https://soa_gw.canadapost.ca/rs/ship/service/USA.XP?contract=0040024030&country=US&country=US"
media_type=“application/vnd.cpc.ship.rate_v2+xml”/><service_name>Priority
Worldwide pak
USA</service_name><price_details>63.320.000.000.0065.06<option_code>DC</option_code><option_name>Delivery
confirmation</option_name><option_price>0</option_price><option_code>SO</option_code><option_name>Signature
option</option_name><option_price>0</option_price><adjustment_code>FUELSC</adjustment_code><adjustment_name>Fuel
surcharge</adjustment_name><adjustment_cost>1.74</adjustment_cost>2.75</price_details><weight_details/><service_standard><am_delivery>false</am_delivery><guaranteed_delivery>false</guaranteed_delivery></service_standard></price_quote><price_quote><service_code>USA.PW.PARCEL</service_code><service_link
rel=“service” href="
https://soa_gw.canadapost.ca:443/rs/ship/service/USA.PW.PARCEL?contract=
https://soa_gw.canadapost.ca/rs/ship/service/USA.PW.PARCEL?contract=0040024030&country=US
004002000
https://soa_gw.canadapost.ca/rs/ship/service/USA.XP?contract=0040024030&country=US&country=US"
media_type=“application/vnd.cpc.ship.rate_v2+xml”/><service_name>Priority
Worldwide parcel
USA</service_name><price_details>70.300.000.000.0072.23<option_code>DC</option_code><option_name>Delivery
confirmation</option_name><option_price>0</option_price><option_code>SO</option_code><option_name>Signature
option</option_name><option_price>0</option_price><adjustment_code>FUELSC</adjustment_code><adjustment_name>Fuel
surcharge</adjustment_name><adjustment_cost>1.93</adjustment_cost>2.75</price_details><weight_details/><service_standard><am_delivery>false</am_delivery><guaranteed_delivery>false</guaranteed_delivery></service_standard></price_quote><price_quote><service_code>USA.SP.AIR</service_code><service_link
rel=“service” href="
https://soa_gw.canadapost.ca:443/rs/ship/service/USA.SP.AIR?contract=
https://soa_gw.canadapost.ca/rs/ship/service/USA.SP.AIR?contract=0040024030&country=US
004002000
https://soa_gw.canadapost.ca/rs/ship/service/USA.XP?contract=0040024030&country=US
&country=US
https://soa_gw.canadapost.ca/rs/ship/service/USA.SP.AIR?contract=0040024030&country=US"
media_type=“application/vnd.cpc.ship.rate_v2+xml”/><service_name>Small
Packet USA
Air</service_name><price_details>16.230.000.000.0016.23</price_details><weight_details/><service_standard><am_delivery>false</am_delivery><guaranteed_delivery>false</guaranteed_delivery></service_standard></price_quote><price_quote><service_code>
USA.TP
http://usa.tp/</service_code><service_link rel=“service” href="
https://soa_gw.canadapost.ca:443/rs/ship/service/USA.TP?contract=
https://soa_gw.canadapost.ca/rs/ship/service/USA.TP?contract=0040024030&country=US
004002000
https://soa_gw.canadapost.ca/rs/ship/service/USA.XP?contract=0040024030&country=US
&country=US
https://soa_gw.canadapost.ca/rs/ship/service/USA.TP?contract=0040024030&country=US"
media_type=“application/vnd.cpc.ship.rate_v2+xml”/><service_name>Tracked
Packet _
USA</service_name><price_details>18.190.000.000.0018.96<option_code>DC</option_code><option_name>Delivery
confirmation</option_name><option_price>0</option_price><adjustment_code>FUELSC</adjustment_code><adjustment_name>Fuel
surcharge</adjustment_name><adjustment_cost>0.77</adjustment_cost>4.25</price_details><weight_details/><service_standard><am_delivery>false</am_delivery><guaranteed_delivery>false</guaranteed_delivery><expected_transit_time>6</expected_transit_time><expected_delivery_date>2015_11_23</expected_delivery_date></service_standard></price_quote><price_quote><service_code>USA.XP</service_code><service_link
rel=“service” href="
https://soa_gw.canadapost.ca:443/rs/ship/service/USA.XP?contract=004002000&country=US
https://soa_gw.canadapost.ca/rs/ship/service/USA.XP?contract=0040024030&country=US"
media_type=“application/vnd.cpc.ship.rate_v2+xml”/><service_name>Xpresspost
USA</service_name><price_details>30.600.000.000.0033.43<option_code>DC</option_code><option_name>Delivery
confirmation</option_name><option_price>0</option_price><option_code>SO</option_code><option_name>Signature
option</option_name><option_price>0</option_price><adjustment_code>FUELSC</adjustment_code><adjustment_name>Fuel
surcharge</adjustment_name><adjustment_cost>2.83</adjustment_cost>9.25</price_details><weight_details/><service_standard><am_delivery>false</am_delivery><guaranteed_delivery>true</guaranteed_delivery><expected_transit_time>3</expected_transit_time><expected_delivery_date>2015_11_18</expected_delivery_date></service_standard></price_quote></price_quotes>On Tuesday, September 22, 2015 at 12:26:32 PM UTC-4, Dominique Dupuis wrote:
First, I’m surprised I could not find an actual guide to migrating codes
from CF to Lucee. I did find a few “notes” from people having done it but
nothing I can go through to search and convert problematic areas of my
codes, systematically. So any help with something like this would be very
appreciated.
The problem I’m trying to fix right now has to do with XmlSearch.
This is the code as it has been working for me in CF10 as well as CF11
<cfset GetArtifactURL =
Replace(XmlSearch(Trim(xmlResponse),“normalize-space(string(//*:link[@rel =
‘label’]/@href))”),“_”,“-”,“all”)>
Here is a sample of a response xml file (with only id numbers manually
changed):
<?xml version="1.0" encoding="UTF-8"?>
00012345670439632119
created
When I test my XMLsearch code at
XPath Expression Testbed, it
does not work, just as it does not work on Lucee.
But on that site this works (I mean it extracts the proper label
link): string(/descendant::link[@rel = ‘label’]/@href)
So I changed my cf code above to:
<cfset GetArtifactURL =
Replace(XmlSearch(Trim(xmlResponse),“normalize-space(string(/descendant::link[@rel
= ‘label’]/@href))”),“_”,“-”,“all”)>
But still no luck, it keeps returning an empty string.
What am I missing. Is this a Lucee problem?
Thank you