ox-2.1.1/ 0000755 0000041 0000041 00000000000 12311544775 012202 5 ustar www-data www-data ox-2.1.1/lib/ 0000755 0000041 0000041 00000000000 12311544775 012750 5 ustar www-data www-data ox-2.1.1/lib/ox.rb 0000644 0000041 0000041 00000006237 12311544775 013733 0 ustar www-data www-data # Copyright (c) 2011, Peter Ohler
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# - Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# - Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# - Neither the name of Peter Ohler nor the names of its contributors may be
# used to endorse or promote products derived from this software without
# specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# === Description:
#
# Ox handles XML documents in two ways. It is a generic XML parser and writer as
# well as a fast Object / XML marshaller. Ox was written for speed as a
# replacement for Nokogiri and for Marshal.
#
# As an XML parser it is 2 or more times faster than Nokogiri and as a generic
# XML writer it is 14 times faster than Nokogiri. Of course different files may
# result in slightly different times.
#
# As an Object serializer Ox is 4 times faster than the standard Ruby
# Marshal.dump(). Ox is 3 times faster than Marshal.load().
#
# === Object Dump Sample:
#
# require 'ox'
#
# class Sample
# attr_accessor :a, :b, :c
#
# def initialize(a, b, c)
# @a = a
# @b = b
# @c = c
# end
# end
#
# # Create Object
# obj = Sample.new(1, "bee", ['x', :y, 7.0])
# # Now dump the Object to an XML String.
# xml = Ox.dump(obj)
# # Convert the object back into a Sample Object.
# obj2 = Ox.parse_obj(xml)
#
# === Generic XML Writing and Parsing:
#
# require 'ox'
#
# doc = Ox::Document.new(:version => '1.0')
#
# top = Ox::Element.new('top')
# top[:name] = 'sample'
# doc << top
#
# mid = Ox::Element.new('middle')
# mid[:name] = 'second'
# top << mid
#
# bot = Ox::Element.new('bottom')
# bot[:name] = 'third'
# mid << bot
#
# xml = Ox.dump(doc)
# puts xml
# doc2 = Ox.parse(xml)
# puts "Same? #{doc == doc2}"
module Ox
end
require 'ox/version'
require 'ox/error'
require 'ox/hasattrs'
require 'ox/node'
require 'ox/comment'
require 'ox/instruct'
require 'ox/cdata'
require 'ox/doctype'
require 'ox/element'
require 'ox/document'
require 'ox/bag'
require 'ox/sax'
require 'ox/ox' # C extension
ox-2.1.1/lib/ox/ 0000755 0000041 0000041 00000000000 12311544775 013376 5 ustar www-data www-data ox-2.1.1/lib/ox/instruct.rb 0000644 0000041 0000041 00000002500 12311544775 015573 0 ustar www-data www-data
module Ox
# An Instruct represents a processing instruction of an XML document. It has a target, attributes, and a value or
# content. The content will be all characters with the exception of the target. If the content follows a regular
# attribute format then the attributes will be set to the parsed values. If it does not follow the attribute formate
# then the attributes will be empty.
class Instruct < Node
include HasAttrs
# The content of the processing instruction.
attr_accessor :content
# Creates a new Instruct with the specified name.
# @param [String] name name of the Instruct
def initialize(name)
super
@attributes = nil
@content = nil
end
alias target value
# Returns true if this Object and other are of the same type and have the
# equivalent value and the equivalent elements otherwise false is returned.
# @param [Object] other Object compare _self_ to.
# @return [Boolean] true if both Objects are equivalent, otherwise false.
def eql?(other)
return false if (other.nil? or self.class != other.class)
return false unless super(other)
return false unless self.attributes == other.attributes
return false unless self.content == other.content
true
end
alias == eql?
end # Instruct
end # Ox
ox-2.1.1/lib/ox/cdata.rb 0000644 0000041 0000041 00000000367 12311544775 015005 0 ustar www-data www-data
module Ox
# CData represents a CDATA element in an XML document.
class CData < Node
# Creates a CDATA element.
# @param value [String] value for the CDATA contents
def initialize(value)
super
end
end # CData
end # Ox
ox-2.1.1/lib/ox/comment.rb 0000644 0000041 0000041 00000000467 12311544775 015374 0 ustar www-data www-data
module Ox
# Coments represent XML comments in an XML document. A comment as value
# attribute only.
class Comment < Node
# Creates a new Comment with the specified value.
# @param value [String] string value for the comment
def initialize(value)
super
end
end # Comment
end # Ox
ox-2.1.1/lib/ox/sax.rb 0000644 0000041 0000041 00000005264 12311544775 014525 0 ustar www-data www-data module Ox
# A SAX style parse handler. The Ox::Sax handler class should be subclasses
# and then used with the Ox.sax_parse() method. The Sax methods will then be
# called as the file is parsed. This is best suited for very large files or
# IO streams.
element.locate("Family/Pete/*")
returns all children of the Pete Element.
# * element.locate("Family/?[1]")
returns the first element in the Family Element.
# * element.locate("Family/?[<3]")
returns the first 3 elements in the Family Element.
# * element.locate("Family/?/@age")
returns the arg attribute for each child in the Family Element.
# * element.locate("Family/*/@type")
returns the type attribute value for decendents of the Family.
# * element.locate("Family/^Comment")
returns any comments that are a child of Family.
#
# @param [String] path path to the Nodes to locate
def locate(path)
return [self] if path.nil?
found = []
pa = path.split('/')
alocate(pa, found)
found
end
# Handles the 'easy' API that allows navigating a simple XML by
# referencing elements and attributes by name.
# @param [Symbol] id element or attribute name
# @return [Element|Node|String|nil] the element, attribute value, or Node identifed by the name
# @raise [NoMethodError] if no match is found
def method_missing(id, *args, &block)
ids = id.to_s
i = args[0].to_i # will be 0 if no arg or parsing fails
nodes.each do |n|
if (n.is_a?(Element) || n.is_a?(Instruct)) && (n.value == id || n.value == ids)
return n if 0 == i
i -= 1
end
end
if instance_variable_defined?(:@attributes)
return @attributes[id] if @attributes.has_key?(id)
return @attributes[ids] if @attributes.has_key?(ids)
end
raise NoMethodError.new("#{ids} not found", name)
end
# @param [Array] path array of steps in a path
# @param [Array] found matching nodes
def alocate(path, found)
step = path[0]
if step.start_with?('@') # attribute
raise InvalidPath.new(path) unless 1 == path.size
if instance_variable_defined?(:@attributes)
step = step[1..-1]
sym_step = step.to_sym
@attributes.each do |k,v|
found << v if ('?' == step or k == step or k == sym_step)
end
end
else # element name
if (i = step.index('[')).nil? # just name
name = step
qual = nil
else
name = step[0..i-1]
raise InvalidPath.new(path) unless step.end_with?(']')
i += 1
qual = step[i..i] # step[i] would be better but some rubies (jruby, ree, rbx) take that as a Fixnum.
if '0' <= qual and qual <= '9'
qual = '+'
else
i += 1
end
index = step[i..-2].to_i
end
if '?' == name or '*' == name
match = nodes
elsif '^' == name[0..0] # 1.8.7 thinks name[0] is a fixnum
case name[1..-1]
when 'Element'
match = nodes.select { |e| e.is_a?(Element) }
when 'String', 'Text'
match = nodes.select { |e| e.is_a?(String) }
when 'Comment'
match = nodes.select { |e| e.is_a?(Comment) }
when 'CData'
match = nodes.select { |e| e.is_a?(CData) }
when 'DocType'
match = nodes.select { |e| e.is_a?(DocType) }
else
#puts "*** no match on #{name}"
match = []
end
else
match = nodes.select { |e| e.is_a?(Element) and name == e.name }
end
unless qual.nil? or match.empty?
case qual
when '+'
match = index < match.size ? [match[index]] : []
when '-'
match = index <= match.size ? [match[-index]] : []
when '<'
match = 0 < index ? match[0..index - 1] : []
when '>'
match = index <= match.size ? match[index + 1..-1] : []
else
raise InvalidPath.new(path)
end
end
if (1 == path.size)
match.each { |n| found << n }
elsif '*' == name
match.each { |n| n.alocate(path, found) if n.is_a?(Element) }
match.each { |n| n.alocate(path[1..-1], found) if n.is_a?(Element) }
else
match.each { |n| n.alocate(path[1..-1], found) if n.is_a?(Element) }
end
end
end
end # Element
end # Ox
ox-2.1.1/metadata.yml 0000644 0000041 0000041 00000004176 12311544775 014515 0 ustar www-data www-data --- !ruby/object:Gem::Specification
name: ox
version: !ruby/object:Gem::Version
version: 2.1.1
platform: ruby
authors:
- Peter Ohler
autorequire:
bindir: bin
cert_chain: []
date: 2014-02-12 00:00:00.000000000 Z
dependencies: []
description: "A fast XML parser and object serializer that uses only standard C lib.\n
\ \nOptimized XML (Ox), as the name implies was written to provide speed
optimized\nXML handling. It was designed to be an alternative to Nokogiri and other
Ruby\nXML parsers for generic XML parsing and as an alternative to Marshal for Object\nserialization. "
email: peter@ohler.com
executables: []
extensions:
- ext/ox/extconf.rb
extra_rdoc_files:
- README.md
files:
- LICENSE
- README.md
- ext/ox/attr.h
- ext/ox/base64.c
- ext/ox/base64.h
- ext/ox/cache.c
- ext/ox/cache.h
- ext/ox/cache8.c
- ext/ox/cache8.h
- ext/ox/cache8_test.c
- ext/ox/cache_test.c
- ext/ox/dump.c
- ext/ox/encode.h
- ext/ox/err.c
- ext/ox/err.h
- ext/ox/extconf.rb
- ext/ox/gen_load.c
- ext/ox/helper.h
- ext/ox/obj_load.c
- ext/ox/ox.c
- ext/ox/ox.h
- ext/ox/parse.c
- ext/ox/sax.c
- ext/ox/sax.h
- ext/ox/sax_as.c
- ext/ox/sax_buf.c
- ext/ox/sax_buf.h
- ext/ox/sax_has.h
- ext/ox/sax_hint.c
- ext/ox/sax_hint.h
- ext/ox/sax_stack.h
- ext/ox/special.c
- ext/ox/special.h
- ext/ox/type.h
- lib/ox.rb
- lib/ox/bag.rb
- lib/ox/cdata.rb
- lib/ox/comment.rb
- lib/ox/doctype.rb
- lib/ox/document.rb
- lib/ox/element.rb
- lib/ox/error.rb
- lib/ox/hasattrs.rb
- lib/ox/instruct.rb
- lib/ox/node.rb
- lib/ox/sax.rb
- lib/ox/version.rb
- lib/ox/xmlrpc_adapter.rb
homepage: http://www.ohler.com/ox
licenses:
- MIT
- GPL-3.0
metadata: {}
post_install_message:
rdoc_options:
- "--main"
- README.md
require_paths:
- lib
- ext
required_ruby_version: !ruby/object:Gem::Requirement
requirements:
- - ">="
- !ruby/object:Gem::Version
version: '0'
required_rubygems_version: !ruby/object:Gem::Requirement
requirements:
- - ">="
- !ruby/object:Gem::Version
version: '0'
requirements: []
rubyforge_project: ox
rubygems_version: 2.2.0
signing_key:
specification_version: 4
summary: A fast XML parser and object serializer.
test_files: []
has_rdoc: true
ox-2.1.1/LICENSE 0000644 0000041 0000041 00000002720 12311544775 013210 0 ustar www-data www-data Copyright (c) 2011, Peter Ohler
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
- Neither the name of Peter Ohler nor the names of its contributors may be
used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
ox-2.1.1/checksums.yaml.gz 0000444 0000041 0000041 00000000413 12311544775 015466 0 ustar www-data www-data ORe9V0D"tt@BEKq(n_zx_>WUŖ;f