Quantcast
Channel: Reading custom values in Ebay RSS feed (XML::RSS module) - Stack Overflow
Viewing all articles
Browse latest Browse all 3

Answer by mob for Reading custom values in Ebay RSS feed (XML::RSS module)

$
0
0

What is the way in which "it doesn't work" from an RSS feed? Do you mean no matches when there should be matches? Or one match where there should be several matches?

One thing that jumps out at me about your regular expression is that you use .*, which can sometimes be greedier than you want. That is, if $item contained the expression

<rx:BuyItNowPrice xmlns:rx="urn:...nts">1395</rx:BuyItNowPrice><rx:CurrentPrice xmlns:rx="urn:...nts">1255</rx:CurrentPrice><rx:BuyItNowPrice xmlns:rx="urn:...nts">1395</rx:BuyItNowPrice><rx:SomeMoreStuff xmlns:rx="urn:...nts">zzz</rx:BuyItNowPrice><rx:CurrentPrice xmlns:rx="urn:...nts">1255</rx:CurrentPrice>

then the first part of your regular expression (\<rx\:CurrentPrice.*\>) will wind up matching everything on lines 2, 3, and 4, plus the first part of line 5 (up to the >). Instead, you might want to use the regular expression1

m/\<rx:CurrentPrice[^>]*>(\d+)\<\/rx:CurrentPrice\>/

which will only match up to the closing </rx:CurrentPrice> tag after a single instance of an opening <rx:CurrentPrice> tag.

1 The other obvious answer is that you really don't want to use a regular expression at all, that regular expressions are inferior tools for parsing XML compared to customized parsing modules, and that all the special cases you will have to deal with using regular expressions will eventually render you unconscious from having repeatedly beaten your head against your desk. See Salgar's answer, for example.


Viewing all articles
Browse latest Browse all 3

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>