Created
October 13, 2018 11:52
-
-
Save agraul/e4e770e78cd49cb49b4327fb4568dea1 to your computer and use it in GitHub Desktop.
Nokigiri OBS Collection parsing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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