Instantly share code, notes, and snippets.

What would you like to do?
One line Xpath expression to create a nodeset
songtypes = ['Cover', 'Original', 'Duet', 'Group']
songtypes.each do |song|
node_xml = doc.xpath('Container/Set/*[contains(name(), "Cover")]')
#I wanted to be able to do the following
FavoriteCover = node_xml.xpath('./*[contains(name(), "Recommended")]')
RegularCover = node_xml.xpath('./*[not(contains(name(), "Recommended"))]')
FavoriteCover = node_xml.xpath('*[contains(name(), "Recommended")]')
RegularCover = node_xml.xpath('*[not(contains(name(), "Recommended"))]')
#But instead I had to resort to a Rails solution
RegularCover = node_xml.find{ |node| !~ /Recommended/ }
FavoriteCover = node_xml.find{ |node| =~ /Recommended/ }
#Do something with the songs here
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment