
Security News
New Website “Is It Really FOSS?” Tracks Transparency in Open Source Distribution Models
A new site reviews software projects to reveal if they’re truly FOSS, making complex licensing and distribution models easy to understand.
== DESCRIPTION:
Used to parse XML files with Nokogiri
== REQUIREMENTS:
nokogiri
== INSTALL:
$ gem build noko_parser.gemspec $ sudo gem install noko_parser-x.x.x.gem
== USAGE:
See examples/monkey.rb and examples/monkeys.xml
Say you have an xml document like below. We are interested in extracting the Monkey elements out of it and embed banana elements inside it.
elephant1 large monkey1 monkeylastname 1 small 2 medium 23 quiet 300 Monkey St Cincinnati Oh 45219 monkey2 monkeylastname 3 large 4 huge 33 loud 301 Monkey St Cincinnati Oh 45219You first define your monkey and banana class and then describe the way to find all the nodes you are looking for and then the properties you want. You can also add class methods to manipulate the data.
module Fruits; end module Animals; end
class Fruits::Banana include NokoParser::Properties nodes :xpath => '//banana'
property :id, :xpath => 'id' property :size, :xpath => 'size'
end
class Animals::Monkey include NokoParser::Properties nodes :xpath => '//monkey'
property :id, :xpath => '.', :attribute => 'id'
property :first_name, :xpath => 'contact/name[@type="first"]'
property :last_name, :xpath => 'contact/name[@type="last"]'
property :age, :xpath => 'yrsold'
property :funny, :xpath => 'personality', :attribute => :hilarious
property :loud, :xpath => 'personality'
property :street, :xpath => 'street'
property :city, :xpath => 'city'
property :state, :xpath => 'state'
property :zip, :xpath => 'zip'
embed :bananas, :xpath => 'bananas', :class => 'Fruits::Banana'
def address [street, city, state].compact.join(", ") + " #{zip}" end
def age @age.to_i end
def funny=(value) @funny = (value == "true" ? true : false) end end
You can then call the Monkey#parse method passing in xml or the Monkey#parse_file method passing in the path to a file.
You will receive an array of monkey objects in return.
irb(main):001:0> require 'pp' => true
irb(main):002:0> monkeys = Animals::Monkey.parse_file('examples/monkeys.xml') => #<Animals::Monkey:0x149cab8 ...>, #<Animals::Monkey:0x14992b4 ...>]
irb(main):003:0> pp monkeys.first #<Animals::Monkey:0x149cab8 @age="23", @bananas= [#<Fruits::Banana:0x149a3f8 @id="1", @size="small">, #<Fruits::Banana:0x1499b4c @id="2", @size="medium">], @city="Cincinnati", @first_name="monkey1", @funny=false, @id=1, @last_name="monkeylastname", @loud="quiet", @state="Oh", @street="300 Monkey St", @zip="45219"> => nil
irb(main):004:0> pp monkeys.last #<Animals::Monkey:0x14992b4 @age="33", @bananas= [#<Fruits::Banana:0x1496c30 @id="3", @size="large">, #<Fruits::Banana:0x1496384 @id="4", @size="huge">], @city="Cincinnati", @first_name="monkey2", @funny=false, @id=2, @last_name="monkeylastname", @loud="loud", @state="Oh", @street="301 Monkey St", @zip="45219"> => nil
irb(main):005:0> monkeys.first.age => 23
irb(main):006:0> monkeys.first.age.class => Fixnum
irb(main):007:0> monkeys.first.address => "300 Monkey St, Cincinnati, Oh 45219"
irb(main):008:0> monkeys.first.funny => false
irb(main):010:0> pp monkeys.first.bananas [#<Fruits::Banana:0x149a3f8 @id="1", @size="small">, #<Fruits::Banana:0x1499b4c @id="2", @size="medium">] => nil
irb(main):004:0> pp monkeys.last.bananas [#<Fruits::Banana:0x1496c30 @id="3", @size="large">, #<Fruits::Banana:0x1496384 @id="4", @size="huge">] => nil
== FEATURES/PROBLEMS:
== LICENSE:
(The MIT License)
Copyright (c) 2008 FIX
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
FAQs
Unknown package
We found that dusty-noko_parser demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A new site reviews software projects to reveal if they’re truly FOSS, making complex licensing and distribution models easy to understand.
Security News
Astral unveils pyx, a Python-native package registry in beta, designed to speed installs, enhance security, and integrate deeply with uv.
Security News
The Latio podcast explores how static and runtime reachability help teams prioritize exploitable vulnerabilities and streamline AppSec workflows.