Skip to content

Instantly share code, notes, and snippets.

@agraul
Created October 13, 2018 11:52
Show Gist options
  • Save agraul/e4e770e78cd49cb49b4327fb4568dea1 to your computer and use it in GitHub Desktop.
Save agraul/e4e770e78cd49cb49b4327fb4568dea1 to your computer and use it in GitHub Desktop.
Nokigiri OBS Collection parsing
require 'multi_xml'
single_bin_response = <<~XML
<collection matches="1">
<binary name="neofetch-git"/>
</collection>
XML
multi_bin_response = <<~XML
<collection matches="2">
<binary name="neofetch-git" />
<binary name="neofetch" />
</collection>
XML
MultiXml.parser = :nokogiri
MultiXml.parse(single_bin_response)
# => {"collection"=>{"binary"=>{"name"=>"neofetch-git"}, "matches"=>"1"}}
MultiXml.parse(multi_bin_response)
# => {"collection"=>{"binary"=>[{"name"=>"neofetch-git"}, {"name"=>"neofetch"}], "matches"=>"2"}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment