libxml-ruby-5.0.3/ 0000755 0000041 0000041 00000000000 14620142101 014004 5 ustar www-data www-data libxml-ruby-5.0.3/libxml-ruby.gemspec 0000644 0000041 0000041 00000003672 14620142101 017627 0 ustar www-data www-data # encoding: utf-8
require 'date'
# Determine the current version of the software
version = File.read('ext/libxml/ruby_xml_version.h').match(/\s*RUBY_LIBXML_VERSION\s*['"](\d.+)['"]/)[1]
Gem::Specification.new do |spec|
spec.name = 'libxml-ruby'
spec.version = version
spec.homepage = 'https://xml4r.github.io/libxml-ruby/'
spec.summary = 'Ruby Bindings for LibXML2'
spec.description = <<-EOS
The Libxml-Ruby project provides Ruby language bindings for the GNOME
Libxml2 XML toolkit. It is free software, released under the MIT License.
Libxml-ruby's primary advantage over REXML is performance - if speed
is your need, these are good libraries to consider, as demonstrated
by the informal benchmark below.
EOS
spec.authors = ['Ross Bamform', 'Wai-Sun Chia', 'Sean Chittenden',
'Dan Janwoski', 'Anurag Priyam', 'Charlie Savage',
'Ryan Johnson']
spec.platform = Gem::Platform::RUBY
spec.bindir = 'bin'
spec.extensions = ['ext/libxml/extconf.rb']
spec.files = Dir.glob(['HISTORY',
'LICENSE',
'libxml-ruby.gemspec',
'MANIFEST',
'Rakefile',
'README.rdoc',
'setup.rb',
'ext/libxml/*.def',
'ext/libxml/*.h',
'ext/libxml/*.c',
'ext/libxml/*.rb',
'ext/vc/*.sln',
'ext/vc/*.vcprojx',
'lib/**/*.rb',
'script/**/*',
'test/**/*'])
spec.test_files = Dir.glob('test/test_*.rb')
spec.required_ruby_version = '>= 2.5'
spec.date = DateTime.now
spec.add_development_dependency('rake-compiler')
spec.add_development_dependency('minitest')
spec.license = 'MIT'
end
libxml-ruby-5.0.3/README.rdoc 0000644 0000041 0000041 00000020620 14620142101 015612 0 ustar www-data www-data = LibXML Ruby
== Overview
The libxml gem provides Ruby language bindings for GNOME's Libxml2
XML toolkit. It is free software, released under the MIT License.
We think libxml-ruby is the best XML library for Ruby because:
* Speed - Its much faster than REXML and Hpricot
* Features - It provides an amazing number of featues
* Conformance - It passes all 1800+ tests from the OASIS XML Tests Suite
== Requirements
libxml-ruby requires Ruby 3.0.0 or higher. It depends on libxml2 to
function properly. libxml2, in turn, depends on:
* libm (math routines: very standard)
* libz (zlib)
* libiconv
If you are running Linux or Unix you'll need a C compiler so the
extension can be compiled when it is installed. If you are running
Windows, then install the x64-mingw-ucr gem or build it yourself using (Ruby
for Windows)[https://rubyinstaller.org/] or directly with msys2[https://msys2.github.io/]
and ucrt64.
== Installation
The easiest way to install libxml-ruby is via RubyGems. To install:
gem install libxml-ruby
If the extension compile process cannot find libxml2, you may need to indicate
the location of the libxml2 configuration utility as it is used to find the
required header and include files. (If you need to indicate a location for the
libxml2 library or header files different than reported by xml2-config,
see the additional configuration options.)
This may be done with RubyGems:
gem install libxml-ruby -- --with-xml2-dir=/path/to/xml2-config
Or bundler:
bundle config build.libxml-ruby --with-xml2-config=/path/to/xml2-config
bundle install libxml-ruby
If you are running Windows, then install the libxml-ruby-x64-mingw32 gem.
The gem includes prebuilt extensions for Ruby 3.2 and 3.3.
The gem also includes a Microsoft VC++ solution and XCode project - these
are very useful for debugging.
libxml-ruby's source codes lives on GitHub[https://github.com/xml4r/libxml-ruby].
== Getting Started
Using libxml is easy. First decide what parser you want to use:
* Generally you'll want to use the LibXML::XML::Parser which provides a tree based API.
* For larger documents that don't fit into memory, or if you prefer an input based API, use the LibXML::XML::Reader.
* To parse HTML files use LibXML::XML::HTMLParser.
* If you are masochistic, then use the LibXML::XML::SaxParser, which provides a callback API.
Once you have chosen a parser, choose a datasource. Libxml can parse files, strings, URIs
and IO streams. For each data source you can specify an LibXML::XML::Encoding, a base uri and
various parser options. For more information, refer the LibXML::XML::Parser.document,
LibXML::XML::Parser.file, LibXML::XML::Parser.io or LibXML:::XML::Parser.string methods (the
same methods are defined on all four parser classes).
== Advanced Functionality
Beyond the basics of parsing and processing XML and HTML documents,
libxml provides a wealth of additional functionality.
Most commonly, you'll want to use its LibXML::XML::XPath support, which makes
it easy to find data inside an XML document. Although not as popular,
LibXML::XML::XPointer provides another API for finding data inside an XML document.
Often times you'll need to validate data before processing it. For example,
if you accept user generated content submitted over the Web, you'll
want to verify that it does not contain malicious code such as embedded scripts.
This can be done using libxml's powerful set of validators:
* DTDs (LibXML::XML::Dtd)
* Relax Schemas (LibXML::XML::RelaxNG)
* XML Schema (LibXML::XML::Schema)
Finally, if you'd like to use XSL Transformations to process data, then install
the {libxslt gem}[https://github.com/xml4r/libxslt-rubygem].
== Usage
For information about using libxml-ruby please refer to its
documentation[http://xml4r.github.io/libxml-ruby]. Some tutorials are also
available[https://github.com/xml4r/libxml-ruby/wiki].
All libxml classes are in the LibXML::XML module. The easiest
way to use libxml is to require 'xml'. This will mixin
the LibXML module into the global namespace, allowing you to
write code like this:
require 'xml'
document = XML::Document.new
However, when creating an application or library you plan to
redistribute, it is best to not add the LibXML module to the global
namespace, in which case you can either write your code like this:
require 'libxml'
document = LibXML::XML::Document.new
Or you can utilize a namespace for your own work and include LibXML into it.
For example:
require 'libxml'
module MyApplication
include LibXML
class MyClass
def some_method
document = XML::Document.new
end
end
end
For simplicity's sake, the documentation uses the xml module in its examples.
== Tests
To run tests you first need to build the shared libary:
rake compile
Once you have build the shared libary, you can then run tests using rake:
rake test
+Build status: {rdoc-image:https://github.com/xml4r/libxml-ruby/actions/workflows/mri.yml/badge.svg}[https://github.com/xml4r/libxml-ruby/actions/workflows/mri.yml]
== Performance
In addition to being feature rich and conformation, the main reason
people use libxml-ruby is for performance. Here are the results
of a couple simple benchmarks recently blogged about on the
Web (you can find them in the benchmark directory of the
libxml distribution).
From http://depixelate.com/2008/4/23/ruby-xml-parsing-benchmarks
user system total real
libxml 0.032000 0.000000 0.032000 ( 0.031000)
Hpricot 0.640000 0.031000 0.671000 ( 0.890000)
REXML 1.813000 0.047000 1.860000 ( 2.031000)
From https://svn.concord.org/svn/projects/trunk/common/ruby/xml_benchmarks/
user system total real
libxml 0.641000 0.031000 0.672000 ( 0.672000)
hpricot 5.359000 0.062000 5.421000 ( 5.516000)
rexml 22.859000 0.047000 22.906000 ( 23.203000)
== Documentation
Documentation is available via rdoc, and is installed automatically with the
gem.
libxml-ruby's {online
documentation}[https://xml4r.github.io/libxml-ruby/rdoc/index.html] is generated
using Hanna, which is a development gem dependency.
Note that older versions of Rdoc, which ship with Ruby 1.8.x, will report
a number of errors. To avoid them, install Rdoc 2.1 or higher. Once you have
installed the gem, you'll have to disable the version of Rdoc that Ruby 1.8.x
includes. An easy way to do that is rename the directory
ruby/lib/ruby/1.8/rdoc to
ruby/lib/ruby/1.8/rdoc_old.
== Support
If you have any questions about using libxml-ruby, please report an issue
on GitHub[https://github.com/xml4r/libxml-ruby/issues].
== Memory Management
libxml-ruby automatically manages memory associated with the
underlying libxml2 library. The bindings create a one-to-one mapping between
Ruby objects and libxml documents and libxml parent nodes (ie, nodes that do not
have a parent and do not belong to a document). In these cases,
the bindings manage the memory. They do this by installing a free
function and storing a back pointer to the Ruby object from the xmlnode
using the _private member on libxml structures. When the Ruby object
goes out of scope, the underlying libxml structure is freed. Libxml
itself then frees all child nodes (recursively).
For all other nodes (the vast majority), the bindings create temporary
Ruby objects that get freed once they go out of scope. Thus there can be
more than one Ruby object pointing to the same xml node. To mostly hide
this from a programmer on the Ruby side, the #eql? and #== methods are
overriden to check if two Ruby objects wrap the same xmlnode. If they do,
then the methods return true. During the mark phase, each of these temporary
objects marks its owning document, thereby keeping the Ruby document object
alive and thus the xmldoc tree.
In the sweep phase of the garbage collector, or when a program ends,
there is no order to how Ruby objects are freed. In fact, the Ruby document
object is almost always freed before any Ruby objects that wrap child nodes.
However, this is ok because those Ruby objects do not have a free function
and are no longer in scope (since if they were the document would not be freed).
== License
See LICENSE for license information.
libxml-ruby-5.0.3/lib/ 0000755 0000041 0000041 00000000000 14620142101 014552 5 ustar www-data www-data libxml-ruby-5.0.3/lib/libxml/ 0000755 0000041 0000041 00000000000 14620142101 016041 5 ustar www-data www-data libxml-ruby-5.0.3/lib/libxml/sax_callbacks.rb 0000644 0000041 0000041 00000012415 14620142101 021163 0 ustar www-data www-data # encoding: UTF-8
module LibXML
module XML
class SaxParser
module Callbacks
# Called for a CDATA block event.
def on_cdata_block(cdata)
end
# Called for a characters event.
def on_characters(chars)
end
# Called for a comment event.
def on_comment(msg)
end
# Called for a end document event.
def on_end_document
end
# Called for a end element event.
def on_end_element_ns(name, prefix, uri)
end
# Called for parser errors.
def on_error(msg)
end
# Called for an external subset event.
def on_external_subset(name, external_id, system_id)
end
# Called for an external subset notification event.
def on_has_external_subset
end
# Called for an internal subset notification event.
def on_has_internal_subset
end
# Called for an internal subset event.
def on_internal_subset(name, external_id, system_id)
end
# Called for 'is standalone' event.
def on_is_standalone
end
# Called for an processing instruction event.
def on_processing_instruction(target, data)
end
# Called for a reference event.
def on_reference(name)
end
# Called for a start document event.
def on_start_document
end
# Called for a start element event.
def on_start_element_ns(name, attributes, prefix, uri, namespaces)
end
end
module VerboseCallbacks
# Called for a CDATA block event.
def on_cdata_block(cdata)
STDOUT << "on_cdata_block" << "\n" <<
" cdata " << cdata << "\n"
STDOUT.flush
end
# Called for a characters event.
def on_characters(chars)
STDOUT << "on_characters" << "\n" <<
" chars " << chars << "\n"
STDOUT.flush
end
# Called for a comment event.
def on_comment(comment)
STDOUT << "on_comment" << "\n" <<
" comment: " << comment << "\n"
STDOUT.flush
end
# Called for a end document event.
def on_end_document
STDOUT << "on_end_document\n"
STDOUT.flush
end
# Called for a end element event.
def on_end_element_ns(name, prefix, uri)
STDOUT << "on_end_element_ns" << "\n" <<
" name: " << name << "\n" <<
" prefix: " << prefix << "\n" <<
" uri: " << uri << "\n"
STDOUT.flush
end
# Called for parser errors.
def on_error(error)
STDOUT << "on_error" << "\n"
" error " << error << "\n"
STDOUT.flush
end
# Called for an external subset event.
def on_external_subset(name, external_id, system_id)
STDOUT << "on_external_subset" << "\n"
" external_id " << external_id << "\n" <<
" system_id " << system_id << "\n"
STDOUT.flush
end
# Called for an external subset notification event.
def on_has_external_subset
STDOUT << "on_has_internal_subset\n"
STDOUT.flush
end
# Called for an internal subset notification event.
def on_has_internal_subset
STDOUT << "on_has_internal_subset\n"
STDOUT.flush
end
# Called for an internal subset event.
def on_internal_subset(name, external_id, system_id)
STDOUT << "on_internal_subset" << "\n"
" external_id " << external_id << "\n" <<
" system_id " << system_id << "\n"
STDOUT.flush
end
# Called for 'is standalone' event.
def on_is_standalone
STDOUT << "on_is_standalone\n"
STDOUT.flush
end
# Called for an processing instruction event.
def on_processing_instruction(target, data)
STDOUT << "on_characters" << "\n"
" target: " << target << "\n" <<
" data: " << data << "\n"
STDOUT.flush
end
# Called for a reference event.
def on_reference(name)
STDOUT << "on_reference:" << "\n" <<
" name:" << name << "\n"
STDOUT.flush
end
# Called for a start document event.
def on_start_document
STDOUT << "on_start_document\n"
STDOUT.flush
end
# Called for a start element event.
def on_start_element_ns(name, attributes, prefix, uri, namespaces)
STDOUT << "on_start_element_ns" << "\n" <<
" name: " << name << "\n" <<
" attr: " << (attributes || Hash.new).inspect << "\n" <<
" prefix: " << prefix << "\n" <<
" uri: " << uri << "\n" <<
" ns_defs: " << (namespaces || Hash.new).inspect << "\n"
STDOUT.flush
end
end
end
end
end libxml-ruby-5.0.3/lib/libxml/attr_decl.rb 0000644 0000041 0000041 00000003617 14620142101 020336 0 ustar www-data www-data # encoding: UTF-8
module LibXML
module XML
class AttrDecl
include Enumerable
# call-seq:
# attr_decl.child -> nil
#
# Obtain this attribute declaration's child attribute(s).
# It will always be nil.
def child
nil
end
# call-seq:
# attr_decl.child? -> (true|false)
#
# Returns whether this attribute declaration has child attributes.
#
def child?
not self.children.nil?
end
# call-seq:
# attr_decl.doc? -> (true|false)
#
# Determine whether this attribute declaration is associated with an
# XML::Document.
def doc?
not self.doc.nil?
end
# call-seq:
# attr_decl.next? -> (true|false)
#
# Determine whether there is a next attribute declaration.
def next?
not self.next.nil?
end
# call-seq:
# attr_decl.parent? -> (true|false)
#
# Determine whether this attribute declaration has a parent .
def parent?
not self.parent.nil?
end
# call-seq:
# attr_decl.prev? -> (true|false)
#
# Determine whether there is a previous attribute declaration.
def prev?
not self.prev.nil?
end
# call-seq:
# attr_decl.node_type_name -> 'attribute declaration'
#
# Returns this attribute declaration's node type name.
def node_type_name
if node_type == Node::ATTRIBUTE_DECL
'attribute declaration'
else
raise(UnknownType, "Unknown node type: %n", node.node_type);
end
end
# call-seq:
# attr_decl.to_s -> string
#
# Returns a string representation of this attribute declaration.
def to_s
"#{name} = #{value}"
end
end
end
end
libxml-ruby-5.0.3/lib/libxml/error.rb 0000644 0000041 0000041 00000005127 14620142101 017524 0 ustar www-data www-data # encoding: UTF-8
module LibXML
module XML
class Error
# Create mapping from domain constant values to keys
DOMAIN_CODE_MAP = [:NO_ERROR, :PARSER, :TREE, :NAMESPACE, :DTD, :HTML, :MEMORY,
:OUTPUT, :IO, :FTP, :HTTP, :XINCLUDE, :XPATH, :XPOINTER, :REGEXP,
:DATATYPE, :SCHEMASP, :SCHEMASV, :RELAXNGP, :RELAXNGV, :CATALOG,
:C14N, :XSLT, :VALID, :CHECK, :WRITER, :MODULE, :I18N, :SCHEMATRONV].inject(Hash.new) do |hash, code|
if const_defined?(code)
hash[const_get(code)] = code
end
hash
end
# Create mapping from error constant values (so need to remove domain_codes) to keys
ERROR_CODE_MAP = Hash.new.tap do |map|
(constants -
DOMAIN_CODE_MAP.values - #Domains
[:NONE, :WARNING, :ERROR, :FATAL] # Levels
).each do |code|
map[const_get(code)] = code
end
end
# Verbose error handler
VERBOSE_HANDLER = lambda do |error|
STDERR << error.to_s << "\n"
STDERR.flush
end
# Quiet error handler
QUIET_HANDLER = lambda do |error|
end
def ==(other)
eql?(other)
end
def eql?(other)
self.code == other.code and
self.domain == other.domain and
self.message == other.message and
self.level == other.level and
self.file == other.file and
self.line == other.line and
self.str1 == other.str1 and
self.str2 == other.str2 and
self.str3 == other.str3 and
self.int1 == other.int1 and
self.int2 == other.int2 and
self.ctxt == other.ctxt and
self.node == other.node
rescue
false
end
def level_to_s
case self.level
when NONE
''
when WARNING
'Warning:'
when ERROR
'Error:'
when FATAL
'Fatal error:'
end
end
def domain_to_s
DOMAIN_CODE_MAP[self.domain].to_s
end
def code_to_s
ERROR_CODE_MAP[self.code].to_s
end
def to_s
msg = super
msg = msg ? msg.strip: ''
if self.line
sprintf("%s %s at %s:%d.", self.level_to_s, msg,
self.file, self.line)
else
sprintf("%s %s.", self.level_to_s, msg)
end
end
end
end
end
LibXML::XML::Error.set_handler(&LibXML::XML::Error::VERBOSE_HANDLER)
libxml-ruby-5.0.3/lib/libxml/schema.rb 0000644 0000041 0000041 00000003742 14620142101 017634 0 ustar www-data www-data module LibXML
module XML
class Schema
module Types
XML_SCHEMA_TYPE_BASIC = 1 # A built-in datatype
XML_SCHEMA_TYPE_ANY = 2
XML_SCHEMA_TYPE_FACET = 3
XML_SCHEMA_TYPE_SIMPLE = 4
XML_SCHEMA_TYPE_COMPLEX = 5
XML_SCHEMA_TYPE_SEQUENCE = 6
XML_SCHEMA_TYPE_CHOICE = 7
XML_SCHEMA_TYPE_ALL = 8
XML_SCHEMA_TYPE_SIMPLE_CONTENT = 9
XML_SCHEMA_TYPE_COMPLEX_CONTENT = 10
XML_SCHEMA_TYPE_UR = 11
XML_SCHEMA_TYPE_RESTRICTION = 12
XML_SCHEMA_TYPE_EXTENSION = 13
XML_SCHEMA_TYPE_ELEMENT = 14
XML_SCHEMA_TYPE_ATTRIBUTE = 15
XML_SCHEMA_TYPE_ATTRIBUTEGROUP = 16
XML_SCHEMA_TYPE_GROUP = 17
XML_SCHEMA_TYPE_NOTATION = 18
XML_SCHEMA_TYPE_LIST = 19
XML_SCHEMA_TYPE_UNION = 20
XML_SCHEMA_TYPE_ANY_ATTRIBUTE = 21
XML_SCHEMA_TYPE_IDC_UNIQUE = 22
XML_SCHEMA_TYPE_IDC_KEY = 23
XML_SCHEMA_TYPE_IDC_KEYREF = 24
XML_SCHEMA_TYPE_PARTICLE = 25
XML_SCHEMA_TYPE_ATTRIBUTE_USE = 26
XML_SCHEMA_FACET_MININCLUSIVE = 1000
XML_SCHEMA_FACET_MINEXCLUSIVE = 1001
XML_SCHEMA_FACET_MAXINCLUSIVE = 1002
XML_SCHEMA_FACET_MAXEXCLUSIVE = 1003
XML_SCHEMA_FACET_TOTALDIGITS = 1004
XML_SCHEMA_FACET_FRACTIONDIGITS = 1005
XML_SCHEMA_FACET_PATTERN = 1006
XML_SCHEMA_FACET_ENUMERATION = 1007
XML_SCHEMA_FACET_WHITESPACE = 1008
XML_SCHEMA_FACET_LENGTH = 1009
XML_SCHEMA_FACET_MAXLENGTH = 1010
XML_SCHEMA_FACET_MINLENGTH = 1011
XML_SCHEMA_EXTRA_QNAMEREF = 2000
XML_SCHEMA_EXTRA_ATTR_USE_PROHIB = 2001
end
end
end
end libxml-ruby-5.0.3/lib/libxml/node.rb 0000644 0000041 0000041 00000020706 14620142101 017320 0 ustar www-data www-data # encoding: UTF-8
require 'stringio'
module LibXML
module XML
class Node
# Determines whether this node has attributes
def attributes?
attributes.length > 0
end
# Create a shallow copy of the node. To create
# a deep copy call Node#copy(true)
def clone
copy(false)
end
# call-seq:
# node.inner_xml -> "string"
# node.inner_xml(:indent => true, :encoding => 'UTF-8', :level => 0) -> "string"
#
# Converts a node's children to a string representation. To include
# the node, use XML::Node#to_s. For more information about
# the supported options, see XML::Node#to_s.
def inner_xml(options = Hash.new)
io = nil
self.each do |node|
xml = node.to_s(options)
# Create the string IO here since we now know the encoding
io = create_string_io(xml) unless io
io << xml
end
io ? io.string : nil
end
# :call-seq:
# node.dup -> XML::Node
#
# Create a shallow copy of the node. To create
# a deep copy call Node#copy(true)
def dup
copy(false)
end
# call-seq:
# node.context(namespaces=nil) -> XPath::Context
#
# Returns a new XML::XPathContext for the current node.
#
# Namespaces is an optional array of XML::NS objects
def context(nslist = nil)
if not self.doc
raise(TypeError, "A node must belong to a document before a xpath context can be created")
end
context = XPath::Context.new(self.doc)
context.node = self
context.register_namespaces_from_node(self)
context.register_namespaces_from_node(self.doc.root)
context.register_namespaces(nslist) if nslist
context
end
# call-seq:
# node.find(namespaces=nil) -> XPath::XPathObject
#
# Return nodes matching the specified xpath expression.
# For more information, please refer to the documentation
# for XML::Document#find.
#
# Namespaces is an optional array of XML::NS objects
def find(xpath, nslist = nil)
self.context(nslist).find(xpath)
end
# call-seq:
# node.find_first(namespaces=nil) -> XML::Node
#
# Return the first node matching the specified xpath expression.
# For more information, please refer to the documentation
# for the #find method.
def find_first(xpath, nslist = nil)
find(xpath, nslist).first
end
# call-seq:
# node.namespacess -> XML::Namespaces
#
# Returns this node's XML::Namespaces object,
# which is used to access the namespaces
# associated with this node.
def namespaces
@namespaces ||= XML::Namespaces.new(self)
end
# ------- Traversal ----------------
# Iterates over this node's attributes.
#
# doc = XML::Document.new('model/books.xml')
# doc.root.each_attr {|attr| puts attr}
def each_attr
attributes.each do |attr|
yield(attr)
end
end
# Iterates over this node's child elements (nodes
# that have a node_type == ELEMENT_NODE).
#
# doc = XML::Document.new('model/books.xml')
# doc.root.each_element {|element| puts element}
def each_element
each do |node|
yield(node) if node.node_type == ELEMENT_NODE
end
end
# Determines whether this node has a parent node
def parent?
not parent.nil?
end
# Determines whether this node has a first node
def first?
not first.nil?
end
# Returns this node's children as an array.
def children
entries
end
# Determines whether this node has a next node
def next?
not self.next.nil?
end
# Determines whether this node has a previous node
def prev?
not prev.nil?
end
# Determines whether this node has a last node
def last?
not last.nil?
end
# ------- Node Types ----------------
# Returns this node's type name
def node_type_name
case node_type
# Most common choices first
when ATTRIBUTE_NODE
'attribute'
when DOCUMENT_NODE
'document_xml'
when ELEMENT_NODE
'element'
when TEXT_NODE
'text'
# Now the rest
when ATTRIBUTE_DECL
'attribute_decl'
when CDATA_SECTION_NODE
'cdata'
when COMMENT_NODE
'comment'
when DOCB_DOCUMENT_NODE
'document_docbook'
when DOCUMENT_FRAG_NODE
'fragment'
when DOCUMENT_TYPE_NODE
'doctype'
when DTD_NODE
'dtd'
when ELEMENT_DECL
'elem_decl'
when ENTITY_DECL
'entity_decl'
when ENTITY_NODE
'entity'
when ENTITY_REF_NODE
'entity_ref'
when HTML_DOCUMENT_NODE
'document_html'
when NAMESPACE_DECL
'namespace'
when NOTATION_NODE
'notation'
when PI_NODE
'pi'
when XINCLUDE_START
'xinclude_start'
when XINCLUDE_END
'xinclude_end'
else
raise(UnknownType, "Unknown node type: %n", node.node_type);
end
end
# Specifies if this is an attribute node
def attribute?
node_type == ATTRIBUTE_NODE
end
# Specifies if this is an attribute declaration node
def attribute_decl?
node_type == ATTRIBUTE_DECL
end
# Specifies if this is an CDATA node
def cdata?
node_type == CDATA_SECTION_NODE
end
# Specifies if this is an comment node
def comment?
node_type == COMMENT_NODE
end
# Specifies if this is an docbook node
def docbook_doc?
node_type == DOCB_DOCUMENT_NODE
end
# Specifies if this is an doctype node
def doctype?
node_type == DOCUMENT_TYPE_NODE
end
# Specifies if this is an document node
def document?
node_type == DOCUMENT_NODE
end
# Specifies if this is an DTD node
def dtd?
node_type == DTD_NODE
end
# Specifies if this is an element node
def element?
node_type == ELEMENT_NODE
end
# Specifies if this is an entity node
def entity?
node_type == ENTITY_NODE
end
# Specifies if this is an element declaration node
def element_decl?
node_type == ELEMENT_DECL
end
# Specifies if this is an entity reference node
def entity_ref?
node_type == ENTITY_REF_NODE
end
# Specifies if this is a fragment node
def fragment?
node_type == DOCUMENT_FRAG_NODE
end
# Specifies if this is a html document node
def html_doc?
node_type == HTML_DOCUMENT_NODE
end
# Specifies if this is a namespace node (not if it
# has a namepsace)
def namespace?
node_type == NAMESPACE_DECL
end
# Specifies if this is a notation node
def notation?
node_type == NOTATION_NODE
end
# Specifies if this is a processiong instruction node
def pi?
node_type == PI_NODE
end
# Specifies if this is a text node
def text?
node_type == TEXT_NODE
end
# Specifies if this is an xinclude end node
def xinclude_end?
node_type == XINCLUDE_END
end
# Specifies if this is an xinclude start node
def xinclude_start?
node_type == XINCLUDE_START
end
alias :child? :first?
alias :children? :first?
alias :child :first
alias :each_child :each
private
def create_string_io(xml)
result = StringIO.new("")
if defined?(::Encoding)
result.set_encoding(xml.encoding)
end
result
end
end
end
end
libxml-ruby-5.0.3/lib/libxml/sax_parser.rb 0000644 0000041 0000041 00000002316 14620142101 020537 0 ustar www-data www-data # encoding: UTF-8
module LibXML
module XML
class SaxParser
# call-seq:
# XML::SaxParser.file(path) -> XML::SaxParser
#
# Creates a new parser by parsing the specified file or uri.
def self.file(path)
context = XML::Parser::Context.file(path)
self.new(context)
end
# call-seq:
# XML::SaxParser.io(io) -> XML::SaxParser
# XML::SaxParser.io(io, :encoding => XML::Encoding::UTF_8) -> XML::SaxParser
#
# Creates a new reader by parsing the specified io object.
#
# Parameters:
#
# encoding - The document encoding, defaults to nil. Valid values
# are the encoding constants defined on XML::Encoding.
def self.io(io, options = {})
context = XML::Parser::Context.io(io)
context.encoding = options[:encoding] if options[:encoding]
self.new(context)
end
# call-seq:
# XML::SaxParser.string(string)
#
# Creates a new parser by parsing the specified string.
def self.string(string)
context = XML::Parser::Context.string(string)
self.new(context)
end
end
end
end libxml-ruby-5.0.3/lib/libxml/attributes.rb 0000644 0000041 0000041 00000000337 14620142101 020557 0 ustar www-data www-data # encoding: UTF-8
module LibXML
module XML
class Attributes
def to_h
inject({}) do |hash, attr|
hash[attr.name] = attr.value
hash
end
end
end
end
end libxml-ruby-5.0.3/lib/libxml/document.rb 0000644 0000041 0000041 00000016071 14620142101 020211 0 ustar www-data www-data # encoding: UTF-8
module LibXML
module XML
class Document
# call-seq:
# XML::Document.document(document) -> XML::Document
#
# Creates a new document based on the specified document.
#
# Parameters:
#
# document - A preparsed document.
def self.document(value)
Parser.document(value).parse
end
# call-seq:
# XML::Document.file(path) -> XML::Document
# XML::Document.file(path, encoding: XML::Encoding::UTF_8,
# options: XML::Parser::Options::NOENT) -> XML::Document
#
# Creates a new document from the specified file or uri.
#
# Parameters:
#
# path - Path to file
# encoding - The document encoding, defaults to nil. Valid values
# are the encoding constants defined on XML::Encoding.
# options - Parser options. Valid values are the constants defined on
# XML::Parser::Options. Mutliple options can be combined
# by using Bitwise OR (|).
def self.file(path, encoding: nil, options: nil)
Parser.file(path, encoding: encoding, options: options).parse
end
# call-seq:
# XML::Document.io(io) -> XML::Document
# XML::Document.io(io, :encoding => XML::Encoding::UTF_8,
# :options => XML::Parser::Options::NOENT
# :base_uri="http://libxml.org") -> XML::Document
#
# Creates a new document from the specified io object.
#
# Parameters:
#
# io - io object that contains the xml to parser
# base_uri - The base url for the parsed document.
# encoding - The document encoding, defaults to nil. Valid values
# are the encoding constants defined on XML::Encoding.
# options - Parser options. Valid values are the constants defined on
# XML::Parser::Options. Mutliple options can be combined
# by using Bitwise OR (|).
def self.io(io, base_uri: nil, encoding: nil, options: nil)
Parser.io(io, base_uri: base_uri, encoding: encoding, options: options).parse
end
# call-seq:
# XML::Document.string(string) -> XML::Document
# XML::Document.string(string, encoding: XML::Encoding::UTF_8,
# options: XML::Parser::Options::NOENT
# base_uri: "http://libxml.org") -> XML::Document
#
# Creates a new document from the specified string.
#
# Parameters:
#
# string - String to parse
# base_uri - The base url for the parsed document.
# encoding - The document encoding, defaults to nil. Valid values
# are the encoding constants defined on XML::Encoding.
# options - Parser options. Valid values are the constants defined on
# XML::Parser::Options. Mutliple options can be combined
# by using Bitwise OR (|).
def self.string(value, base_uri: nil, encoding: nil, options: nil)
Parser.string(value, base_uri: base_uri, encoding: encoding, options: options).parse
end
# Returns a new XML::XPathContext for the document.
#
# call-seq:
# document.context(namespaces=nil) -> XPath::Context
#
# Namespaces is an optional array of XML::NS objects
def context(nslist = nil)
context = XPath::Context.new(self)
context.node = self.root
context.register_namespaces_from_node(self.root)
context.register_namespaces(nslist) if nslist
context
end
# Return the nodes matching the specified xpath expression,
# optionally using the specified namespace. For more
# information about working with namespaces, please refer
# to the XML::XPath documentation.
#
# call-seq:
# document.find(xpath, nslist=nil) -> XML::XPath::Object
#
# Parameters:
# * xpath - The xpath expression as a string
# * namespaces - An optional list of namespaces (see XML::XPath for information).
#
# document.find('/foo', 'xlink:http://www.w3.org/1999/xlink')
#
# IMPORTANT - The returned XML::Node::Set must be freed before
# its associated document. In a running Ruby program this will
# happen automatically via Ruby's mark and sweep garbage collector.
# However, if the program exits, Ruby does not guarantee the order
# in which objects are freed
# (see http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/17700).
# As a result, the associated document may be freed before the node
# list, which will cause a segmentation fault.
# To avoid this, use the following (non-ruby like) coding style:
#
# nodes = doc.find('/header')
# nodes.each do |node|
# ... do stuff ...
# end
# # nodes = nil # GC.start
def find(xpath, nslist = nil)
self.context(nslist).find(xpath)
end
# Return the first node matching the specified xpath expression.
# For more information, please refer to the documentation
# for XML::Document#find.
def find_first(xpath, nslist = nil)
find(xpath, nslist).first
end
# Returns this node's type name
def node_type_name
case node_type
when XML::Node::DOCUMENT_NODE
'document_xml'
when XML::Node::DOCB_DOCUMENT_NODE
'document_docbook'
when XML::Node::HTML_DOCUMENT_NODE
'document_html'
else
raise(UnknownType, "Unknown node type: %n", node.node_type);
end
end
# :enddoc:
# Specifies if this is an document node
def document?
node_type == XML::Node::DOCUMENT_NODE
end
# Specifies if this is an docbook node
def docbook_doc?
node_type == XML::Node::DOCB_DOCUMENT_NODE
end
# Specifies if this is an html node
def html_doc?
node_type == XML::Node::HTML_DOCUMENT_NODE
end
def dump
warn('Document#dump is deprecated. Use Document#to_s instead.')
self.to_s
end
def format_dump
warn('Document#format_dump is deprecated. Use Document#to_s instead.')
self.to_s
end
def debug_dump
warn('Document#debug_dump is deprecated. Use Document#debug instead.')
self.debug
end
def debug_dump_head
warn('Document#debug_dump_head is deprecated. Use Document#debug instead.')
self.debug
end
def debug_format_dump
warn('Document#debug_format_dump is deprecated. Use Document#to_s instead.')
self.to_s
end
def reader
warn('Document#reader is deprecated. Use XML::Reader.document(self) instead.')
XML::Reader.document(self)
end
end
end
end
libxml-ruby-5.0.3/lib/libxml/namespaces.rb 0000644 0000041 0000041 00000002320 14620142101 020502 0 ustar www-data www-data # encoding: UTF-8
module LibXML
module XML
class Namespaces
# call-seq:
# namespace.default -> XML::Namespace
#
# Returns the default namespace for this node or nil.
#
# Usage:
# doc = XML::Document.string('')
# ns = doc.root.namespaces.default_namespace
# assert_equal(ns.href, 'http://schemas.xmlsoap.org/soap/envelope/')
def default
find_by_prefix(nil)
end
# call-seq:
# namespace.default_prefix = "string"
#
# Assigns a name (prefix) to the default namespace.
# This makes it much easier to perform XML::XPath
# searches.
#
# Usage:
# doc = XML::Document.string('')
# doc.root.namespaces.default_prefix = 'soap'
# node = doc.root.find_first('soap:Envelope')
def default_prefix=(prefix)
# Find default prefix
ns = find_by_prefix(nil)
raise(ArgumentError, "No default namespace was found") unless ns
Namespace.new(self.node, prefix, ns.href)
end
end
end
end libxml-ruby-5.0.3/lib/libxml/schema/ 0000755 0000041 0000041 00000000000 14620142101 017301 5 ustar www-data www-data libxml-ruby-5.0.3/lib/libxml/schema/element.rb 0000644 0000041 0000041 00000000523 14620142101 021257 0 ustar www-data www-data # encoding: UTF-8
module LibXML
module XML
class Schema::Element
def min_occurs
@min
end
def max_occurs
@max
end
def required?
!min_occurs.zero?
end
def array?
max_occurs > 1
end
def elements
type.elements
end
end
end
end
libxml-ruby-5.0.3/lib/libxml/schema/attribute.rb 0000644 0000041 0000041 00000000405 14620142101 021630 0 ustar www-data www-data # encoding: UTF-8
module LibXML
module XML
class Schema::Attribute
REQUIRED = 1
OPTIONAL = 2
def default
node['default']
end
def required?
occurs == REQUIRED
end
end
end
end
libxml-ruby-5.0.3/lib/libxml/schema/type.rb 0000644 0000041 0000041 00000001056 14620142101 020611 0 ustar www-data www-data module LibXML
module XML
class Schema::Type
def kind_name
Schema::Types.constants.find { |k| Schema::Types.const_get(k) == kind }
end
def annonymus_subtypes
elements.select { |_, e| e.type.name.nil? }
end
def annonymus_subtypes_recursively(parent=nil)
annonymus_subtypes.map do |element_name, e|
[{[parent, element_name].compact.join('::') => e.type},
e.type.annonymus_subtypes_recursively(element_name)]
end.flatten
end
end
end
end
libxml-ruby-5.0.3/lib/libxml/hpricot.rb 0000644 0000041 0000041 00000003651 14620142101 020043 0 ustar www-data www-data # encoding: UTF-8
## Provide hpricot API for libxml. Provided by Michael Guterl,
## inspired by http://thebogles.com/blog/an-hpricot-style-interface-to-libxml
#
#class String
# def to_libxml_doc
# xp = XML::Parser.new
# xp.string = self
# xp.parse
# end
#end
#
#module LibXML
# module XML
# class Document
# alias :search :find
# end
#
# class Node
# # find the child node with the given xpath
# def at(xpath)
# self.find_first(xpath)
# end
#
# # find the array of child nodes matching the given xpath
# def search(xpath)
# results = self.find(xpath).to_a
# if block_given?
# results.each do |result|
# yield result
# end
# end
# return results
# end
#
# def /(xpath)
# search(xpath)
# end
#
# # return the inner contents of this node as a string
# def inner_xml
# child.to_s
# end
#
# # alias for inner_xml
# def inner_html
# inner_xml
# end
#
# # return this node and its contents as an xml string
# def to_xml
# self.to_s
# end
#
# # alias for path
# def xpath
# self.path
# end
#
# def find_with_default_ns(xpath_expr, namespace=nil)
# find_base(xpath_expr, namespace || default_namespaces)
# end
#
# def find_first_with_default_ns(xpath_expr, namespace=nil)
# find_first_base(xpath_expr, namespace || default_namespaces)
# end
#
## alias_method :find_base, :find unless method_defined?(:find_base)
## alias_method :find, :find_with_default_ns
## alias_method :find_first_base, :find_first unless method_defined?(:find_first_base)
## alias_method :find_first, :find_first_with_default_ns
## alias :child? :first?
## alias :children? :first?
## alias :child :first
# end
# end
#end libxml-ruby-5.0.3/lib/libxml/attr.rb 0000644 0000041 0000041 00000005157 14620142101 017350 0 ustar www-data www-data # encoding: UTF-8
module LibXML
module XML
class Attr
include Enumerable
# call-seq:
# attr.child? -> (true|false)
#
# Returns whether this attribute has child attributes.
#
def child?
not self.children.nil?
end
# call-seq:
# attr.doc? -> (true|false)
#
# Determine whether this attribute is associated with an
# XML::Document.
def doc?
not self.doc.nil?
end
# call-seq:
# attr.last? -> (true|false)
#
# Determine whether this is the last attribute.
def last?
self.last.nil?
end
# call-seq:
# attr.next? -> (true|false)
#
# Determine whether there is a next attribute.
def next?
not self.next.nil?
end
# call-seq:
# attr.ns? -> (true|false)
#
# Determine whether this attribute has an associated
# namespace.
def ns?
not self.ns.nil?
end
# call-seq:
# attr.namespacess -> XML::Namespaces
#
# Returns this node's XML::Namespaces object,
# which is used to access the namespaces
# associated with this node.
def namespaces
@namespaces ||= XML::Namespaces.new(self)
end
#
# call-seq:
# attr.parent? -> (true|false)
#
# Determine whether this attribute has a parent.
def parent?
not self.parent.nil?
end
# call-seq:
# attr.prev? -> (true|false)
#
# Determine whether there is a previous attribute.
def prev?
not self.prev.nil?
end
# Returns this node's type name
def node_type_name
if node_type == Node::ATTRIBUTE_NODE
'attribute'
else
raise(UnknownType, "Unknown node type: %n", node.node_type);
end
end
# Iterates nodes and attributes
def siblings(node, &blk)
if n = node
loop do
blk.call(n)
break unless n = n.next
end
end
end
def each_sibling(&blk)
siblings(self,&blk)
end
alias :each_attr :each_sibling
alias :each :each_sibling
def to_h
inject({}) do |h,a|
h[a.name] = a.value
h
end
end
def to_a
inject([]) do |ary,a|
ary << [a.name, a.value]
ary
end
end
def to_s
"#{name} = #{value}"
end
end
end
end libxml-ruby-5.0.3/lib/libxml/tree.rb 0000644 0000041 0000041 00000001770 14620142101 017332 0 ustar www-data www-data # encoding: UTF-8
module LibXML
module XML
class Tree # :nodoc:
ELEMENT_NODE = Node::ELEMENT_NODE
ATTRIBUTE_NODE = Node::ATTRIBUTE_NODE
TEXT_NODE = Node::TEXT_NODE
CDATA_SECTION_NODE = Node::CDATA_SECTION_NODE
ENTITY_REF_NODE = Node::ENTITY_REF_NODE
ENTITY_NODE = Node::ENTITY_NODE
PI_NODE = Node::PI_NODE
COMMENT_NODE = Node::COMMENT_NODE
DOCUMENT_NODE = Node::DOCUMENT_NODE
DOCUMENT_TYPE_NODE = Node::DOCUMENT_TYPE_NODE
DOCUMENT_FRAG_NODE = Node::DOCUMENT_FRAG_NODE
NOTATION_NODE = Node::NOTATION_NODE
HTML_DOCUMENT_NODE = Node::HTML_DOCUMENT_NODE
DTD_NODE = Node::DTD_NODE
ELEMENT_DECL = Node::ELEMENT_DECL
ATTRIBUTE_DECL = Node::ATTRIBUTE_DECL
ENTITY_DECL = Node::ENTITY_DECL
NAMESPACE_DECL = Node::NAMESPACE_DECL
XINCLUDE_START = Node::XINCLUDE_START
XINCLUDE_END = Node::XINCLUDE_END
DOCB_DOCUMENT_NODE = Node::DOCB_DOCUMENT_NODE
end
end
end libxml-ruby-5.0.3/lib/libxml/parser.rb 0000644 0000041 0000041 00000007761 14620142101 017675 0 ustar www-data www-data # encoding: UTF-8
module LibXML
module XML
class Parser
# call-seq:
# XML::Parser.document(document) -> XML::Parser
#
# Creates a new parser for the specified document.
#
# Parameters:
#
# document - A preparsed document.
def self.document(doc)
context = XML::Parser::Context.document(doc)
self.new(context)
end
# call-seq:
# XML::Parser.file(path) -> XML::Parser
# XML::Parser.file(path, encoding: XML::Encoding::UTF_8,
# options: XML::Parser::Options::NOENT) -> XML::Parser
#
# Creates a new parser for the specified file or uri.
#
# Parameters:
#
# path - Path to file
# base_uri - The base url for the parsed document.
# encoding - The document encoding, defaults to nil. Valid values
# are the encoding constants defined on XML::Encoding.
# options - Parser options. Valid values are the constants defined on
# XML::Parser::Options. Mutliple options can be combined
# by using Bitwise OR (|).
def self.file(path, base_uri: nil, encoding: nil, options: nil)
context = XML::Parser::Context.file(path)
context.base_uri = base_uri if base_uri
context.encoding = encoding if encoding
context.options = options if options
self.new(context)
end
# call-seq:
# XML::Parser.io(io) -> XML::Parser
# XML::Parser.io(io, encoding: XML::Encoding::UTF_8,
# options: XML::Parser::Options::NOENT
# base_uri: "http://libxml.org") -> XML::Parser
#
# Creates a new parser for the specified io object.
#
# Parameters:
#
# io - io object that contains the xml to parser
# base_uri - The base url for the parsed document.
# encoding - The document encoding, defaults to nil. Valid values
# are the encoding constants defined on XML::Encoding.
# options - Parser options. Valid values are the constants defined on
# XML::Parser::Options. Mutliple options can be combined
# by using Bitwise OR (|).
def self.io(io, base_uri: nil, encoding: nil, options: nil)
context = XML::Parser::Context.io(io)
context.base_uri = base_uri if base_uri
context.encoding = encoding if encoding
context.options = options if options
self.new(context)
end
# call-seq:
# XML::Parser.string(string)
# XML::Parser.string(string, encoding: XML::Encoding::UTF_8,
# options: XML::Parser::Options::NOENT
# base_uri: "http://libxml.org") -> XML::Parser
#
# Creates a new parser by parsing the specified string.
#
# Parameters:
#
# string - The string to parse
# base_uri - The base url for the parsed document.
# encoding - The document encoding, defaults to nil. Valid values
# are the encoding constants defined on XML::Encoding.
# options - Parser options. Valid values are the constants defined on
# XML::Parser::Options. Multiple options can be combined
# by using Bitwise OR (|).
def self.string(string, base_uri: nil, encoding: nil, options: nil)
context = XML::Parser::Context.string(string)
context.base_uri = base_uri if base_uri
context.encoding = encoding if encoding
context.options = options if options
self.new(context)
end
def self.register_error_handler(proc)
warn('Parser.register_error_handler is deprecated. Use Error.set_handler instead')
if proc.nil?
Error.reset_handler
else
Error.set_handler(&proc)
end
end
end
end
end libxml-ruby-5.0.3/lib/libxml/html_parser.rb 0000644 0000041 0000041 00000007675 14620142101 020725 0 ustar www-data www-data # encoding: UTF-8
module LibXML
module XML
class HTMLParser
# call-seq:
# XML::HTMLParser.file(path) -> XML::HTMLParser
# XML::HTMLParser.file(path, encoding: XML::Encoding::UTF_8,
# options: XML::HTMLParser::Options::NOENT) -> XML::HTMLParser
#
# Creates a new parser by parsing the specified file or uri.
#
# Parameters:
#
# path - Path to file to parse
# encoding - The document encoding, defaults to nil. Valid values
# are the encoding constants defined on XML::Encoding.
# options - Parser options. Valid values are the constants defined on
# XML::HTMLParser::Options. Mutliple options can be combined
# by using Bitwise OR (|).
def self.file(path, encoding: nil, options: nil)
context = XML::HTMLParser::Context.file(path)
context.encoding = encoding if encoding
context.options = options if options
self.new(context)
end
# call-seq:
# XML::HTMLParser.io(io) -> XML::HTMLParser
# XML::HTMLParser.io(io, encoding: XML::Encoding::UTF_8,
# options: XML::HTMLParser::Options::NOENT
# base_uri: "http://libxml.org") -> XML::HTMLParser
#
# Creates a new reader by parsing the specified io object.
#
# Parameters:
#
# io - io object that contains the xml to parser
# base_uri - The base url for the parsed document.
# encoding - The document encoding, defaults to nil. Valid values
# are the encoding constants defined on XML::Encoding.
# options - Parser options. Valid values are the constants defined on
# XML::HTMLParser::Options. Mutliple options can be combined
# by using Bitwise OR (|).
def self.io(io, base_uri: nil, encoding: nil, options: nil)
context = XML::HTMLParser::Context.io(io)
context.base_uri = base_uri if base_uri
context.encoding = encoding if encoding
context.options = options if options
self.new(context)
end
# call-seq:
# XML::HTMLParser.string(string)
# XML::HTMLParser.string(string, encoding: XML::Encoding::UTF_8,
# options: XML::HTMLParser::Options::NOENT
# base_uri: "http://libxml.org") -> XML::HTMLParser
#
# Creates a new parser by parsing the specified string.
#
# Parameters:
#
# string - String to parse
# base_uri - The base url for the parsed document.
# encoding - The document encoding, defaults to nil. Valid values
# are the encoding constants defined on XML::Encoding.
# options - Parser options. Valid values are the constants defined on
# XML::HTMLParser::Options. Mutliple options can be combined
# by using Bitwise OR (|).
def self.string(string, base_uri: nil, encoding: nil, options: nil)
context = XML::HTMLParser::Context.string(string)
context.base_uri = base_uri if base_uri
context.encoding = encoding if encoding
context.options = options if options
self.new(context)
end
# :enddoc:
def file=(value)
warn("XML::HTMLParser#file is deprecated. Use XML::HTMLParser.file instead")
@context = XML::HTMLParser::Context.file(value)
end
def io=(value)
warn("XML::HTMLParser#io is deprecated. Use XML::HTMLParser.io instead")
@context = XML::HTMLParser::Context.io(value)
end
def string=(value)
warn("XML::HTMLParser#string is deprecated. Use XML::HTMLParser.string instead")
@context = XML::HTMLParser::Context.string(value)
end
end
end
end
libxml-ruby-5.0.3/lib/libxml/namespace.rb 0000644 0000041 0000041 00000002577 14620142101 020335 0 ustar www-data www-data # encoding: UTF-8
module LibXML
module XML
class Namespace
include Comparable
include Enumerable
# call-seq:
# namespace1 <=> namespace2
#
# Compares two namespace objects. Namespace objects are
# considered equal if their prefixes and hrefs are the same.
def <=>(other)
if self.prefix.nil? and other.prefix.nil?
self.href <=> other.href
elsif self.prefix.nil?
-1
elsif other.prefix.nil?
1
else
self.prefix <=> other.prefix
end
end
# call-seq:
# namespace.each {|ns| .. }
#
# libxml stores namespaces in memory as a linked list.
# Use the each method to iterate over the list. Note
# the first namespace in the loop is the current namespace.
#
# Usage:
# namespace.each do |ns|
# ..
# end
def each
ns = self
while ns
yield ns
ns = ns.next
end
end
# call-seq:
# namespace.to_s -> "string"
#
# Returns the string represenation of a namespace.
#
# Usage:
# namespace.to_s
def to_s
if self.prefix
"#{self.prefix}:#{self.href}"
else
self.href
end
end
end
end
end libxml-ruby-5.0.3/lib/xml.rb 0000644 0000041 0000041 00000000720 14620142101 015676 0 ustar www-data www-data # encoding: UTF-8
# This file loads libxml and adds the LibXML namespace
# to the toplevel for conveneience. The end result
# is to have XML:: universally exposed.
#
# It is recommend that you only load this file for libs
# that do not have their own namespace, eg. administrative
# scripts, personal programs, etc. For other applications
# require 'libxml' instead and include LibXML into your
# app/libs namespace.
require 'libxml'
include LibXML libxml-ruby-5.0.3/lib/xml/ 0000755 0000041 0000041 00000000000 14620142101 015352 5 ustar www-data www-data libxml-ruby-5.0.3/lib/xml/libxml.rb 0000644 0000041 0000041 00000000203 14620142101 017161 0 ustar www-data www-data # encoding: UTF-8
# This is here for backward compatibility.
#
# TODO: DEPRECATE!
require 'libxml.rb'
include LibXML
libxml-ruby-5.0.3/lib/libxml.rb 0000644 0000041 0000041 00000000145 14620142101 016366 0 ustar www-data www-data # encoding: UTF-8
#
# This include is deprecated, use libxml-ruby instead!
require 'libxml-ruby' libxml-ruby-5.0.3/lib/libxml-ruby.rb 0000644 0000041 0000041 00000001265 14620142101 017351 0 ustar www-data www-data # encoding: UTF-8
# Load the C-based binding.
begin
RUBY_VERSION =~ /(\d+.\d+)/
require "#{$1}/libxml_ruby"
rescue LoadError
require "libxml_ruby"
end
# Load Ruby supporting code.
require 'libxml/error'
require 'libxml/parser'
require 'libxml/document'
require 'libxml/namespaces'
require 'libxml/namespace'
require 'libxml/node'
require 'libxml/attributes'
require 'libxml/attr'
require 'libxml/attr_decl'
require 'libxml/tree'
require 'libxml/html_parser'
require 'libxml/sax_parser'
require 'libxml/sax_callbacks'
#Schema Interface
require 'libxml/schema'
require 'libxml/schema/type'
require 'libxml/schema/element'
require 'libxml/schema/attribute'
libxml-ruby-5.0.3/HISTORY 0000644 0000041 0000041 00000103673 14620142101 015102 0 ustar www-data www-data = Release History
== 5.0.3 / 2024-03-11
* Update xmlStructuredErrorFunc to be backwards compatible
== 5.0.2 / 2024-01-08
* Fix broken DTD creation (DTD name is not required)
== 5.0.1 / 2024-01-08
* Fix broken Document#io method that was broken by switching Parsers to use keyword arguments
== 5.0.0 / 2024-01-07
* This release is major version bump because it removes access to global parser options
that libxml2 version 2.12.0 deprecated (see https://gitlab.gnome.org/GNOME/libxml2/-/releases/v2.12.0)
In the unlikely event your code uses these options, then you will need to update it.
Specifically, instead of setting global parser options, pass them directly to either Parsers
or ParserContexts when creating them. Options are defined as constants in
LibXML::XML::Parser::Options and LibXML::HTML::Parser::Options
* Update Parser initialize methods to take keyword parameters instead of a hash table (you may have to update your code due to this change)
* Fix broken compilation with libxml2 version 2.12.0 (due to libxml2 header changes)
* Add support for Ruby 3.3.*
* Remove support for Ruby 2.7.* (gem should still work but is no longer tested)
== 4.1.2 / 2023-11-04
* Fix Ruby warnings about undefined allocators (yuuji.yaginuma, Christopher Sahnwaldt)
* Fix Schema::Element required? and array? (John Andrews)
* Remove SchemaElement#minOccurs and SchemaElement#maxOccurs since they actually did not work (Charlie Savage)
* Fix typo: XPatch -> XPath (Christopher Sahnwaldt)
* Introduce new alternative Homebrew installation search paths to extconf makefile (Pierce Brooks)
== 4.1.1 / 2023-05-01
* Fix compile warning (or error) for input_callbacks_register_input_callbacks (Charlie Savage)
* Remove call to deprecated function htmlDefaultSAXHandlerInit (Charlie Savage)
== 4.1.0 / 2023-04-30
* Fix compile warning (or error) for rxml_encoding_to_rb_encoding (Charlie Savage)
* Breaking - Remove LibXML::XML.features since its uses functionality deprecated in LibXML (Charlie Savage)
== 4.0.0 / 2022-12-28
* Breaking - Remove support for XPointer since libxml2 has deprecated it and will remove it (Charlie Savage)
* Breaking - Remove support for ancient setup.rb script (Charlie Savage)
== 3.2.4 / 2022-10-29
* Support libxml2 version 2.10.2 (Charlie Savage)
* Reduce number of globally included C header files (Charlie Savage)
== 3.2.3 / 2022-05-22
* Change some getter methods to instance variables with attr_accessors for easier debuggability (David Hansen)
* Add a number of tests related to schemas (David Hansen)
* Add schema.imported_elements so we can find imported elements (David Hansen)
* Fix segfault under windows when dereferencing a pre-existing error where the node has already been freed (David Hansen)
* Update to change name from imported_elements to imported_ns_elements and return a hash of hashes for namespaced elements (David Hansen)
* Only call xmlGetFeaturesList if LIBXML_LEGACY_ENABLED is defined. Most distros still ship libxml2 with legacy features enabled, but this will change (Nick Wellnhofer)
* Update GitHub Actions to use ruby/setup-ruby (Greg)
* Fix memory leak in rxml_node_path, node.path (vovanmozg)
== 3.2.2 / 2022-01-15
* Switch to Github actions for CI/CD (Greg)
* Test fixes (Greg, Sergio Durigan Junior)
* Fix typo on test/test_sax_parser.rb (Sergio Durigan Junior)
* Update homepage in gemspec (Pirate Praveen Arimbrathodiyil)
== 3.2.1 / 2020-11-05
* Fix incorrect handling of encodings when using XMLWriter.io (Charlie Savage)
* Clean up README (Richard Michael)
== 3.2.0 / 2020-05-09 Charlie Savage
* Fix crash when creating an empty DTD
* Modernize tests to use Bundler to load gem
* Add libxml-ruby.rb file so gem loads in expected way.
* Add support for xmlSaveNoEmptyTags.
* Clean up extconf.rb file
== 3.1.0 / 2018-02-03 Charlie Savage
* Fix segmentation fault when adding one node to another node (Charlie Savage)
* Fix deprecated "assert_equal(nil, expected)" calls. #148 and #151. (utilum)
* Remove assigned but unused variables. #150 (utilum)
* Add Gemfile. #146. (Dorian Marié)
* Remove duplicate hash key in setup.rb. #147. (Dorian Marié)
* Fix gemspec by requiring Date. #149 (utilum)
* Restore default internal encoding after tests are completed. #123 (Charlie Savage)
* Remove duplicate method definitions. #145. (Charlie Savage)
* Remove SchemaElement#minOccurs and SchemaElement#maxOccurs since they actually did not work (Charlie Savage)
* Rename test files to follow Ruby conventions (Charlie Savage)
* Fix handling of node returned by Reader#expand. #142. (Charlie Savage)
* Add Travis Build support (Charlie Savage)
* Fix Fixnum deprecation (Charlie Savage)
* Cleanup schema code (Charlie Savage)
* Update Visual Studio project to 2017 (Charlie Savage)
== 3.0.0 / 2017-02-07 Charlie Savage
* Revamp how libxml-ruby manages memory. Instead of trying to return the same ruby object for each xmlnode,
the bindings now create wrapper ruby objects as needed which are then freed at the end of use.
This allows most memory management to be handled by libxml itself. Ruby only manages the lifespan of
documents and parent xml nodes. When those go out of scope, the underlying libxml objects are also freed.
This implementation requires almost no overhead, plays nicely with Nokogiri and appears to work much
better (Charlie Savage).
* Change XML::Node#eql? API. Nodes are now considered equal only if they wrap the same underlying
libxml node. Previously, they would also be considered equal if they contained the same content
(Charlie Savage)
* Change XML::Reader.expand API. Previously it would automatically instantiate a reader document so
the an xpath expression could be used to search the returned node. Now you should first call
reader.doc (Charlie Savage)
* Update Visual Studio project for Visual Studio 15 - requires ruby 2.4+ (Charlie Savage)
* Remove APIs that have been deprecated for several years (Charlie Savage)
== 2.9.0 / 2016-06-13 Charlie Savage
* Revamp libxml-ruby's memory management to not cause crashes when used with Nokogiri (James Laird-Wah)
* Fix garbage collection issue that sometimes caused the library to hang (Charlie Savage)
* Improved multi-threading support (Charlie Savage)
* Fix crash sometimes caused by a xml node being being freed twice (Charlie Savage)
* Fix memory leak when setting the text content of a node (Charlie Savage)
* Set a default task in the Rakefile - use "test" (Robert Haines)
* Add "hanna_gudao" gem and add "rake-compiler" to develpoment dependencies (Robert Haines)
* Use Process.getrlimit instead of `ulimit` in the tests (Robert Haines)
* Build on smartos (Steven Williamson)
* Fix compiler warnings (Charlie Savage)
* Add Xcode project for easier debugging on OSX (Charlie Savage)
* Switch from unit test to minitest (Charlie Savage)
== 2.8.0 / 2015-01-09 Charlie Savage
* Use RbConfig instead of Config in extconf.rb (Robert Haines)
* Correct xpath documentation XML (Bill Mill)
* Correct from_string method documentation (Bill Mill)
* Fix compile error with debug not enabled in libxml (Patrick Ziegler)
* Update gemspec to include license (Charlie Savage)
* In XML::Writer prevent writing to io while being GCed (Brett Gibson)
== 2.7.0 / 2013-08-13 Charlie Savage
* Don't call rb_warning in GC mark function (Dirkjan Bussink)
* Set libxml error handler when a libxml-ruby error handler is set (Geoffrey Giesemann)
* Fix tests for nil TypeErrors for ruby 2.0=< (Geoffrey Giesemann)
* Fix segmentation fault for issue #62 (Charlie Savage)
* Add #node_type method to dtd (Charlie Savage)
* Fixing equality check of LibXML::XML::Error against other objects (Michał Szajbe)
* Fix #63, XML::Writer.set_quote_char UT, wrong expected string (julp)
* Fix potential segfault when GC occurs while creating ns from xpath (Timothy Elliott)
* Fix for #59, segmentation fault after failure to load external schema (Clifford Heath)
== 2.6.0 / 2013-02-16 Charlie Savage
* Fix uninitialized constant LibXML::XML::Error::I18N (NameError) that occurred
with older versions of libxml.
* Various updates/fixes to new XML::Writer class and update how flushing works (julp)
== 2.5.0 / 2013-01-27 Charlie Savage
* Compatibility with older versions for IO::write (rb_io_bufwrite is specific to ruby >= 1.9.3?)
and symbols are VALUE not ID (julp).
* Fix version for xmlTextWriterSetQuoteChar, it appeared in libxml2 2.9.0, last version (julp)
* Update use of LIBXML_VERSION (julp).
* Fix misuse of rb_scan_args (julp).
* Update documentation, including DTD docs and added XML Writer (julp).
* Added a new XML::Writer class (julp).
* Improved xml reader api and add namespace support. Note that passing a numeric value
to XML::Reader::move_to_attribute has been deprecated. Instead you should now
use #move_to_attribute_no. (julp).
* Improve error handling and messages (Jarl Friis)
== 2.4.0 / 2012-12-14 Charlie Savage
* Support libxml 2.9.0 (Daniel Veillard)
* Extensive new interfaces for xml schema functionality including suppor for
schemal elements, types, facets and attributes (Anton Sozontov)
* Fix Encoding#from_s bug and update docs (Nikita Afanasenko)
* Node#content= encoding (Nikita Afanasenko)
== 2.3.3 / 2012-07-01 Charlie Savage
* Add LibXML::XML::Error.get_handler (Carsten Zimmermann)
* Fix variable name in example (Marcus)
== 2.3.2 / 2012-03-20 Charlie Savage
* Define various canonicalize constants to support libxml2 versions
older than 1.1.25 (thanks Apple!)
== 2.3.1 / 2012-03-20 Charlie Savage
* Yanked - didn't fix the OSX canonicalize issue
== 2.3.0 / 2012-03-18 Charlie Savage
* Add ability to insert new PI-nodes into the xmltree (Axel Struebing).
* Added full pass-through access to libxml2 xmlC14NDocDumpMemory method via
LibXML::XML::Document#canonicalize method with optional arguments.
* Added full test data for C14N based off of W3C spec.
(http://www.w3.org/TR/xml-c14n#Examples)
* Update sax handler to support encodings on Ruby 1.9 and higher.
== 2.2.2 / 2011-08-29 Charlie Savage
* ++API CHANGE+++
Reader#relax_ng_validate now takes a RelaxNG object. This is
what the documentation has always said it takes, but it previously
took a string. In addition, it now returns true or false instead of 0 or -1.
Reader#schema_validate now takes a Schema object. This is
what the documentation has always said it takes, but it previously
took a string. In addition, it now returns true or false instead of 0 or -1.
Fixes GitHub issue #30.
* Added Parser::Context#close and HTMLParser::Context#close methods that
allow the underlying io stream (file, string, etc) to be closed. Once a
parser is done parsing its data, it now calls one of these methods.
This means that if you parse thousands of files at the same time,
without running Ruby's garbage colllector, you won't get a too
many files open error. Fixes GitHub issue #29.
* Fixed bug where Node#inner_xml caused an error when it had no child nodes.
Fixes GitHub issues #31
* Don't require 'rake' in the gemspec to avoid annoying Bundler bugs
== 2.2.1 / 2011-08-13 Charlie Savage
* Packaging fix - include the custom .def file in the gem.
== 2.2.0 / 2011-08-09 Charlie Savage
* Update encoding support for Ruby 1.9 so that libxml-ruby returns
strings encoded in UTF-8. This change was required since libxml internally
stores strings in UTF-8. The exceptions to this rule are the #to_s methods
which return UTF-8 by default but can return other encodings if requested.
== 2.1.2 / 2011-08-03 Charlie Savage
* Fix segmentation fault that could occur when an XPathContext was marked
before it was fully initialized (Charlie Savage).
* Add mark method to document to mark all nodes currently being accessed
by ruby. This make Ruby Enterprise Edition happy (Charlie Savage).
== 2.1.1 / 2011-07-31 Charlie Savage
* Switch to using def files to control library exports (Charlie Savage).
== 2.1.0 / 2011-07-31 Charlie Savage
* Ruby 1.9.3 compatability (Charlie Savage).
* Added XPath expression <-> Ruby value conversion methods (Jens Wille).
* Extracted rxml_xpath_to_value from rxml_xpath_context_find (Jens Wille).
* Adapted rxml_xpath_from_value from Gregoire Lejeune's ruby-xslt
library, see https://github.com/glejeune/ruby-xslt (Jens Wille).
* Allow calling #find on nodes returned from Reader (Charlie Savage).
* Change document handling in XPath::Context to address segmentation fault on
Ruby Enterprise Edition (Charlie Savage).
* Update gemspec file to work directly with bundler thereby allowing git
repository to be used as gem (Charlie Savage).
* Support gem buld (Charlie Savage).
* Simplify memory management of attributes namespaces to fix
segmentation faults that occurred when using Ruby 1.9.3 (Charlie Savage).
== 2.0.8 / 2011-06-23 Charlie Savage
* Add in 2 new HTML Parser constants - NODEFDTD and NOIMPLIED.
* Fix compile issue on Ruby 1.9.3
== 2.0.6 / 2011-05-23 Charlie Savage
* Fix segfault that sometimes occurred when looking up encodings on 1.9.
In some cases the Ruby encoding infrastructure was not properly
initialized (nkriege).
== 2.0.5 / 2011-05-05 Charlie Savage
* Document#validate_dtd would sometimes cause segmentation faults due to
an improperly initialized data structure (Charlie Savage)
== 2.0.4 / 2011-05-02 Charlie Savage
* Fix compile issues on platforms using older versions of libxml2.
The problem as using a C14N constants that was added to libxml2
in July 2009 (Charlie Savage).
== 2.0.3 / 2011-05-01 Charlie Savage
* The biggest change in this release is supporting the use of libxml-ruby in
native background Ruby threads. Previously, the use of libxml-ruby in
background threads in Ruby 1.9.x and higher would often cause
segmentation faults. This has now been fixed (Charlie Savage).
* Update Reader#expand so that returned node correctly remembers its
encoding in Ruby 1.9.x (zerebubuth).
* Add check to verify a node has not been deleted. This can happen when
a ruby variable holds a reference to a child node that gets freed
when its parent gets freed. Previously when this happened a
segmentation fault would occur, now an exception is raised (Charlie Savage, fixes
RubyForge #26839.
* Do not unlink nodes before internal validations have run - avoids
segmentation faults caused by freeing a node twice (Charlie Savage).
* Add support for Document#canonicalization (Victor Lin).
* Fix memory leak in Reader#lookup_namespace (Charlie Savage).
* Fix memory leak in Reader#[] (Nathan Kriege).
* Fix usage of @io instance variable (Jeffrey Taylor)
* Removed old sax error handling code that has been fixed in newer
versions of libxml (Charlie Savage).
* Code cleanup - remove unused variables and commented out code (Charlie Savage)
* Minor text changes and documentation fixes (Charlie Savage).
* Fix documentation error (fixes RubyForge #26888).
* Update documentation for Document#validation* methods (fixes RubyForge #24833).
* Update documentation and test (fixes Ruby Forge Issue #28770).
* Updated documentation in README (Anurag Priyam):
1. rake doc does not work; use rake rdoc.
2. gem mislav-hanna does not exist; use hanna.
3. rake rdoc 'depends' on hanna; no need of RDOCOPTS
4. Point to the github issue tracker instead of Ruby Forge
5. Point to the github (gh-pages) site for docs
* Add tc_error to test suite (Charlie Savage).
* Add sax test (Stanislav O.Pogrebnyak).
== 2.0.2 / 2011-04-17 Charlie Savage
* Added binaries for windows (Charlie Savage).
* Update Ruby 1.9 encoding handling to support libxml versions older than
version 2.6.26 which was released on June 6, 2006 (Charlie Savage).
* Add publish_with_docs rake task - combines publishing the
website and docs (Anurag Priyam).
* Correctly copy the documentation directory (Anurag Priyam)
* Use relative link for rdoc so the links are correct on
both rubyforge and github (Anurag Priyam).
* Update Rakefile to use Hanna RDco template (Charlie Savage).
* Update dates on license file (Charlie Savage).
* Add api to allow setting of attribute namespaces. Fixes issue #10 (Charlie Savage).
* Remove old hack to call the on_error method. This hack isn't needed anymore
since a better workaround was put in place in the parser context. Fixes
This fixes issue #12 (Charlie Savage).
* Remove references to passing blocks to validation functions. The blocks are no
longer called since the bindings use libxml's structured error handling. See
issue #6 (Charlie Savage).
* Fix up comment in Document and Node. See issue #8 (Charlie Savage).
* Update website text (Charlie Savage).
== 2.0.0 / 2011-04-16 Charlie Savage
* Ruby 1.9.2 support. The biggest addition is encoding support.
Strings returned by the libxml bindings are now set to the encoding
of the underlying xml document (Charlie Savage).
* Rubinius compatability. Removed unnecessary use of RHASH_TBL (Aman Gupta)
* Added .gemspec file (Dudley Flanders).
* Updated Windows checks to take into account mingw32 (Yaohan Chen).
* Fix memory leak in Reader#Expand (Szymon Nowak).
* Fix memory leaks in Reader#read_string, Reader#read_inner_xml
and Reader#read_outer_xml (Sean Geoghegan).
* Node#space_preserve= was backwards (Dudley Flanders)
* Fixed typo in readme, added rdoc extension (Loren Sands-Ramshaw).
* Switched to Rake Compiler (Charlie Savage).
* Use xmlMalloc() memory for ctxt->sax structure. Sometimes the ctxt->sax pointer
may not be zeroed in rxml_sax_parser_parse(), for example when exception is raised
in one of callbacks. This lets xmlFreeParserCtxt() clean this up (Alexey I. Froloff).
* Added a rake task to publish the website to github. Moved the jekyll website to
web directory (Anurag Priyam).
* Modernize project metadata and layout (7rans)
== 1.1.3 / 2009-03-18 Charlie Savage
* Improve performance 10 to 20% by turning on libxml2's dictionary
feature that allows parsers to reuse previously parsed strings.
* Fix XML::Node#remove! to work correctly with libxml's dictionary feature.
* Correctly set up parser context options.
* Simplify DOM modification code (Node#next=, Node#prev=, Node#sibling=) and
update documentation.
* Deprecated Node#add_child and Node#child=, use Node#<< instead
* Fix documentation for Node#<<
* Added Document#import to enable moving nodes from one document
to another document.
== 1.1.2 / 2009-03-12 Charlie Savage
* Added XML::Node#inner_xml helper method.
* Fix segmentation that could occur when calling the mark function on a
previously freed node.
== 1.1.1 / 2009-03-10 Charlie Savage
* Fix - Only include extra html parser context methods for versions of libxml
older than 2.6.27.
== 1.1.0 / 2009-03-09 Charlie Savage
* Fix bug caused by the mark function being called on partially initialized
attributes.
* Revert back to libxml2's internal memory manager.
== 1.0.0 / 2009-03-05 Charlie Savage
* OS X (Charlie Savage). Update bindings to support the default installed
version of libxml2 (2.6.16) on OS X 10.5 and the latest version available
via MacPorts.
== 0.9.9 / 2009-03-05 Charlie Savage
* Ruby 1.9.1 support (Charlie Savage). libxml-ruby now compiles and runs on either
1.8.6 and 1.9.1. With 1.8.6 all tests should pass while on 1.9.1 all but
for encoding tests pass. The port to Ruby 1.9.1 revealed two memory
allocation bugs (one with dtds, one with nodes) which are now fixed.
* Better OS X support (Joe Khoobyar). The default version of libxml2
on OS X 10.5 is fairly old, resulting in this link error:
NSLinkModule() error
dyld: Symbol not found: _htmlNewParserCtxt
This can be fixed by using MacPorts to get a newer version of libxml2.
To make use of MacPorts, the build script has been updated to use xml2-config.
This can be fine-tuned using the new --with-xml2-config / --without-xml2-config
options to extconf.rb (default is --without-xml2-config to match existing behavior).
* Greatly reduced memory usage (Joe Khoobyar).
See http://rubyforge.org/pipermail/libxml-devel/2009-February/001375.html.
* Add Document#xhtml? and document#node_type methods (Joe Khoobyar)
* Add XPath::Object#last (Joe Khoobyar)
* Provide finer control over CDATA nodes on a parser by parser basis (Joe Khoobyar).
* Bug fix - Namespaces were incorrectly merged with attributes in the new sax2
handler (Charlie Savage).
* Bug fix - Support iterating over nodes and attributes even with blocks
that call remove! (Charlie Savage)
* Bug fix - If reader.node is NULL, return nil instead of crashing (Charlie Savage)
* Bug fix - Dtd's owned by documents were freed twice in some circumstances (Joe Khoobyar).
* Bug fix - Fix output escaping on attributes nodes (Joe Khoobyar).
* Bug fix - Make sure IO objects are not garbage collected when used
as parser sources (Charlie Savage).
== 0.9.8 / 2009-1-24 Charlie Savage
* Refactored XML::Parser, XML::HTMLParser, XML::SaxParser and
XML::Reader to have consistent APIs. All the parsers
now take a context object in their constructors, allowing fine
grained control over the parsers for advanced use cases. These
API changes are backwards compatible except
for XML::Reader, which now takes an optional hash table as a
second parameter in its various constructors versus an optional
boolean value.
* Updated all APIs to use the encoding constants defined
in XML::Encoding versus string values. This API change
is not backwards compatible.
* Added support for attribute declarations in DTD's via the new
XML::AttrDecl class (Len Lattanzi)
* Support libxml's content escaping capabilities for text nodes by
wrapping libxml's "xmlStringText" and "xmlStringTextNoenc"
(Joe Khoobyar).
* Updated XML::Reader#read API to return true if a node was read,
false if node was not read and raises an exception on an error.
Previously #read returned 1 if a node was read, 0 if a node was
not read and -1 for an error. This change is not backwards
compatible, but provides a more natural interface for Ruby by
allowing code like this:
while reader.read
# do stuff
end
* Changed XML::Error exception objects to return copies of nodes that
cause parse errors instead of the original node. This prevents
segmentation faults when the error is reraised.
* Added XML::Reader#node method.
* Fixed compile errors on OS X which uses an older version of libxml.
* Fixed memory leak when performing XPath searches.
* Fixed rdocs.
* Don't override libxml's default settings for entity substitution and
loading external DTDs. This may break some code - you may need to
add in a call to XML.default_substitute_entities = true or
XML.default_load_external_dtd = true.
== 0.9.7 / 2008-12-08 Charlie Savage
* Added SAX2 support. SAX handlers now define two new callbacks,
on_start_element_ns and on_end_element_ns methods. These
new callbacks support namespaces, making them superior to the older
callbacks on_start_element and on_end_element methods. The old callbacks
are still supported, but may be deprecated in the future depending
on community feedback.
* Added SAX support for libxml's structured error handling.
That menas sax handlers now define a new callback, on_error,
which takes one parameter, an instance of XML::Error. The older
on_parser_error, on_parser_warning and on_parser_fatal_error
callbacks are no longer suported so you must port your code.
Note that the older callbacks took one string parameter, instead of
an XML::Error object.
* Experimental work-around for libxml error handling bug - see
http://mail.gnome.org/archives/xml/2008-December/msg00014.html
for more information.
* Fix compilation bugs on Solaris.
* Fix Rdoc compilation bug.
== 0.9.6 / 2008-12-08 Charlie Savage
* Refactored namespace handling. The existing, and inconsistent,
namespace methods defined on XML::Node have been deprecated.
They have been replaced by a the new XML::Namespaces class.
Use this class to inspect a node's namespace, its default
namespace, its namespace definitions and which namespaces
are in scope. It can be accessed via the the
XML::Node#namespaces method.
* Rationalized XML::Document#save, XML::Document#to_s and
XML::Node#to_s to take an optional hash table of parameters
that control how output is generated. Supported parameters
include setting indentation on or off, the indentation level
and the output encoding. This is an API change and may break
existing calls to XML::Document#save. However, the previous
API was broken - setting the encoding resulted in an error so
its unlikely anyone is using it.
* Rationalized XML::Document#debug, XML::Node#debug, XML::XPath::XPathObject#Debug.
* Deprecated a number of duplicate dump* and debug_* methods in
XML::Document and XML::Node.
* Additional Ruby 1.9.1 compatability fixes.
* Cleaned up header file guards.
== 0.9.5 / 2008-11-29 Charlie Savage
* Ruby 1.9.1 preview release compatability (Felipe Contreras)
* Update Node#remove! to return the removed node and to set
its document to nil. This allows the node to be either
moved to another document, another part of the same document
or to be freed on the next garbage collection once its
references have gone out of scope.
* Fix bug where XPathExpression#compile mistakenly overwrote
RegExp#compile.
* Update Node to use standard ruby allocators and initializers.
* Update HTML parser to be more forgiving of invalid documents.
* Update include paths for Darwin Ports on OS X.
* Updated C code base to use BSD/Allman style
== 0.9.4 / 2008-11-24 Charlie Savage
* Update HTML parser so that it can read files, strings and io
streams.
* Update HTML parser to support user specified encodings.
* Additional C code cleanup.
== 0.9.3 / 2008-11-22 Charlie Savage
* Fixed segmentation fault caused by documents being freed
before xpath results that referenced the document (take 2).
* Allowed sax parser to use io stream
* Combined encoding and input classes
* Cleaned up C code - removed remaining legacy structures,
added static to most methods, changed C namespace from ruby_xml
to rxml
== 0.9.2 / 2008-11-19 Charlie Savage
* Add support for compiled XPath expressions (donated by Pavel Valodzka)
* Fixes for compiling on OS X 10.5.4 and 10.5.5
== 0.9.1 / 2008-11-18 Charlie Savage
* Expose LibXML's encoding support via a new Encoding object.
* Revamp error handling to be much easier to use. Errors are now
wrapped by the new XML::Error class and are thrown as exceptions
when it is appropriate.
* Fixed segmentation fault caused by documents being freed
before xpath results that referenced the document.
* Add Node#register_default_namespace to simplify default namespace handling.
* Significantly improve documentation
* A number of bug fixes and patches.
== 0.9.0 / 2008-11-18 Charlie Savage
* Version 0.9.0 was removed due to packaging errors.
== 0.8.3 / 2008-07-21 Charlie Savage
* Missed several files in last release
== 0.8.2 / 2008-07-21 Charlie Savage
* To use LibXML you can either require 'xml' or require 'libxml'.
The differences is that require 'xml' mixes the LibXML module into
the global namespace, thereby allowing you to write code such
as document = XML::Document.new. Note that this is different
from 0.8.0 and 0.8.1 and may require updating your code.
* Support RelaxNG validation (thanks to Morus Walter)
* Support passing IO objects to XmlReaders (thanks to Tom Hughes)
* Fix segmentation fault caused by adding an attribute to a CDATA node
* Moved node checking functions from C to Ruby
* Improved Windows support - libxml-ruby should now work out of the box.
* Improved Windows support - turned on libxml's zlib and iconv support.
== 0.8.1 / 2008-07-09 Charlie Savage
* Reimplmented Node#each_attr for backwards compatability
* Moved node type test to Ruby.
== 0.8.0 / 2008-07-09 Charlie Savage
* Fixed bug in returning attributes from XPath results
* Fixed DOM traversal methods
* Changed Node#children to return an array of nodes
* Fixed bug in returning attributes from XPath results
* Refactored XPath support, providing more user hooks in the XPath::Context class
* Added Node#properties for backwards compatibility
* Updated setup.rb
* Added more tests
* Updated rdocs and README file
* Moved libxml into LibXML namespace
== 0.7.0 / 2008-07-09 Charlie Savage
* Added new attributes class to provide a more natural way of working with attributes
* Fixed XML::Attr to better support namespaces
* Added documentation on how to use namespaces with XPath
* Removed allocation of extraneous structures used to wrap nodes, namespaces and attributes
* Cleaned up tests and added new test suite
* Updated rdocs and README file
* Cleaned out most of the bug list
== 0.6.0 / 2008-07-01 Charlie Savage
* Fixed memory allocation errors in Windows. On Windows, it is essential that the same library that allocates memory must free it. Thus ALLOC calls must be matched to ruby_xfree calls, which they were not. In addition, in one case Ruby was allocating memory to be freed by libxml. On Windows, that's a segmentation fault. On Linux it might fly, but still seems like a bad idea.
* Fixed segmentation fault in xml reader expand (same xml tree freed twice)
* Applied a number of patches from Tom Bagby, including fixes for xpath segmentation faults and fixes for various memory leaks
* Cleaned up a number of compiler warnings
* Renamed libxml_so.so to libxml_ruby.so (same for xslt). That wasn't actually my original intention, but um, it kind of sort of happened. It should not be noticeable from an end-user perspective.
* Added rake files for building with MingW
* Added rake files for packing gems. Note that I did this outside the existing rake tasks because I didn't see how they were actually building the gems.
* Cleaned up the tests and added a few more based on bug reports from the Tracker and mailing list.
* Cleaned out the patch queue and went through about 1/2 the bug list
=== 2007-11-16 "Dan Janowski"
* Merged Dan's MEM2 branch to trunk.
== 0.5.3 /
=== 2007-11-16 "Dan Janowski"
* Merged Dan's MEM2 branch to trunk.
== 0.5.2 / 2007-10-10
=== 2007-10-10 "Dan Janowski"
* (Dan, fill in the major points of the changes you made up to here -thanks)
=== 2007-01-14 "Laurent Sansonetti"
* Added some preliminary RDoc comments for XML::Reader.
=== 2006-12-05 "Laurent Sansonetti"
* Added XML::Reader, a set of bindings to the xmlTextReader API.
== 0.3.8.4 / 2006-12-02
=== 2006-04-15 "Ross Bamform"
* Implemented SAX parser callback handling.
=== 2006-04-12 "Ross Bamford"
* Integrated and tested community patches.
* Defined XML::Node (hash) equality in terms of XML representation.
=== 2006-04-12 "Tim Yamin"
* Fixed XML::Node#content inoperable bug (plasmaroo) [patch]
* Fixed memory leak in same
=== 2006-04-12 "Mark Van Holstyn"
* Added XML::Node::Set#first (mvette13) [patch]
* Added XML::Node::Set#empty?
* Fixed XML::Node::Set#to_a
* Added XML::Node#find_first
* Added XML::Node#remove!
=== 2006-03-27 "Ross Bamford"
* Integrated contributed XML::Parser.register_error_handler patch (rosco)
=== 2006-02-27 "Ross Bamford"
* Fixed all multiple symbol definitions for -fno-common.
* Removed OSX -fno-common workaround.
== 0.3.6 / 2006-02-23
=== 2006-02-21 "Ross Bamford"
* Patched extconf.rb with OSX -fno-common workaround
* Added gem and packaging support to Rakefile
* Moved version update to Rakefile
* Removed legacy project utility scripts
=== 2005-02-19 "Ross Bamford"
* Fixed doublefree bug in ruby_xml_attr.
* Fixed small leak in parser
=== 2005-12-18 "Ross Bamford"
* Updated for GCC 4.0 (community patches)
* Fixed default validation bug
* Refactored project, removed outdated files, cleaned up tests.
* Added RDoc documentation across .c files.
* Fixed up a few strings.
=== 2004-04-04 "Mangler Jurgen"
* ruby_xml_node.cz: fixed ruby_xml_node_property_set. The ill-behaviour
was, that there was added a second attribute of the same
name, when you were setting the value of an already existing
attribute.
=== 2004-03-17 "Lukas Svoboda"
* ruby_xml_node.c: ruby_xml_node_to_s now returns XML subtree dump.
=== 2004-02-27 "Martin Povolny"
* ruby_xml_node.c: added XML::Node.copy, this makes possible building
of xml documents from nodes taken from other xml documents
without making ruby SIGSEGV (see tests/copy_bug.rb).
=== 2004-02-26 "Martin Povolny"
* ruby_xml_dtd.c, ruby_xml_dtd.h, ruby_xml_schema.c, ruby_xml_schema.h:
more work on validation, now you can actually validate
document using dtd or xml schema, also solved warning and
error propagation (see tests/{dtd|schema}-test.rb).
=== 2003-12-30 "Martin Povolny"
* ruby_xml_dtd.c, ruby_xml_dtd.h, ruby_xml_schema.c, ruby_xml_schema.h:
prelimitary support for dtd and schema validation
=== 2003-09-15 "Martin Povolny"
* ruby_xml_input_cbg.c, libxml.c: added class InputCallbacks to make
possible registering custom input callbacks
handlers (xmlRegisterInputCallbacks) written in ruby
=== 2003-08-01 "Martin Povolny"
* ruby_xml_document.c: corrected argument handling in ruby_xml_document_find
* ruby_xml_node.c: corrected argument handling in ruby_xml_node_find
libxml-ruby-5.0.3/test/ 0000755 0000041 0000041 00000000000 14620142101 014763 5 ustar www-data www-data libxml-ruby-5.0.3/test/test_node_comment.rb 0000644 0000041 0000041 00000001544 14620142101 021022 0 ustar www-data www-data # encoding: UTF-8
require_relative './test_helper'
class NodeCommentTest < Minitest::Test
def setup
xp = LibXML::XML::Parser.string('')
@doc = xp.parse
assert_instance_of(LibXML::XML::Document, @doc)
@root = @doc.root
end
def test_libxml_node_add_comment_01
@root << LibXML::XML::Node.new_comment('mycomment')
assert_equal '',
@root.to_s.gsub(/\n\s*/,'')
end
def test_libxml_node_add_comment_02
@root << LibXML::XML::Node.new_comment('mycomment')
assert_equal 'comment',
@root.child.node_type_name
end
def test_libxml_node_add_comment_03
@root << el = LibXML::XML::Node.new_comment('mycomment')
el << "_this_is_added"
assert_equal '',
@root.to_s.gsub(/\n\s*/,'')
end
end
libxml-ruby-5.0.3/test/test_node_pi.rb 0000644 0000041 0000041 00000001732 14620142101 017767 0 ustar www-data www-data # encoding: UTF-8
require_relative './test_helper'
class NodePiTest < Minitest::Test
def setup
xp = LibXML::XML::Parser.string('')
@doc = xp.parse
assert_instance_of(LibXML::XML::Document, @doc)
@root = @doc.root
end
def test_libxml_node_add_pi_01
@root << LibXML::XML::Node.new_pi('mypi')
assert_equal '',
@root.to_s.gsub(/\n\s*/,'')
end
def test_libxml_node_add_pi_02
@root << LibXML::XML::Node.new_pi('mypi')
assert_equal 'pi',
@root.child.node_type_name
end
def test_libxml_node_add_pi_03
@root << el = LibXML::XML::Node.new_pi('mypi')
el << "_this_is_added"
assert_equal '',
@root.to_s.gsub(/\n\s*/,'')
end
def test_libxml_node_add_pi_04
@root << LibXML::XML::Node.new_pi('mypi','mycontent')
assert_equal '',
@root.to_s.gsub(/\n\s*/,'')
end
end
libxml-ruby-5.0.3/test/test_xpath_context.rb 0000644 0000041 0000041 00000005226 14620142101 021244 0 ustar www-data www-data # encoding: UTF-8
require_relative './test_helper'
require "tempfile"
class TestXPathContext < Minitest::Test
SOAP_PREFIX = 'soap'
SOAP_URI = 'http://schemas.xmlsoap.org/soap/envelope/'
NS0_PREFIX = 'ns0'
NS0_URI = 'http://services.somewhere.com'
def setup
doc = LibXML::XML::Document.file(File.join(File.dirname(__FILE__), 'model/soap.xml'))
@context = LibXML::XML::XPath::Context.new(doc)
end
def teardown()
@context = nil
end
def test_no_ns
error = assert_raises(LibXML::XML::Error) do
@context.find('/soap:Envelope')
end
assert_equal("Error: Undefined namespace prefix.", error.to_s)
end
def test_ns_register
@context.register_namespace(SOAP_PREFIX, SOAP_URI)
@context.register_namespace(NS0_PREFIX, NS0_URI)
nodes = @context.find('/soap:Envelope/soap:Body/ns0:getManufacturerNamesResponse')
assert_equal(1, nodes.length)
end
def test_ns_register_string
@context.register_namespaces("#{SOAP_PREFIX}:#{SOAP_URI}")
@context.register_namespaces("#{NS0_PREFIX}:#{NS0_URI}")
nodes = @context.find('/soap:Envelope/soap:Body/ns0:getManufacturerNamesResponse')
assert_equal(1, nodes.length)
end
def test_ns_register_array
@context.register_namespaces(["#{SOAP_PREFIX}:#{SOAP_URI}", "#{NS0_PREFIX}:#{NS0_URI}"])
nodes = @context.find('/soap:Envelope/soap:Body/ns0:getManufacturerNamesResponse')
assert_equal(1, nodes.length)
end
def test_ns_register_hash
@context.register_namespaces(SOAP_PREFIX => SOAP_URI,
NS0_PREFIX => NS0_URI)
nodes = @context.find('/soap:Envelope/soap:Body/ns0:getManufacturerNamesResponse')
assert_equal(1, nodes.length)
end
def test_ns_register_node
@context.register_namespaces_from_node(@context.doc.root)
nodes = @context.find('/soap:Envelope')
assert_equal(1, nodes.length)
end
def test_node
@context.register_namespaces_from_node(@context.doc.root)
nodes = @context.find('soap:Body')
assert_equal(0, nodes.length)
@context.node = @context.doc.root.child.next
nodes = @context.find('soap:Body')
assert_equal(0, nodes.length)
end
def test_cache
@context.enable_cache
@context.enable_cache(10)
@context.disable_cache
end
def test_require_doc
doc = LibXML::XML::Document.file(File.join(File.dirname(__FILE__), 'model/soap.xml'))
error = assert_raises(TypeError) do
@context = LibXML::XML::XPath::Context.new(doc.root)
end
assert_equal("Supplied argument must be a document or node.", error.to_s)
end
end libxml-ruby-5.0.3/test/test_namespace.rb 0000644 0000041 0000041 00000003306 14620142101 020305 0 ustar www-data www-data # encoding: UTF-8
require_relative './test_helper'
class TestNS < Minitest::Test
def setup
file = File.join(File.dirname(__FILE__), 'model/soap.xml')
@doc = LibXML::XML::Document.file(file)
end
def teardown
@doc = nil
end
def test_create_ns
node = LibXML::XML::Node.new('foo')
ns = LibXML::XML::Namespace.new(node, 'my_namepace', 'http://www.mynamespace.com')
assert_equal(ns.prefix, 'my_namepace')
assert_equal(ns.href, 'http://www.mynamespace.com')
end
def test_create_default_ns
node = LibXML::XML::Node.new('foo')
ns = LibXML::XML::Namespace.new(node, nil, 'http://www.mynamespace.com')
assert_nil(ns.prefix)
assert_equal(ns.href, 'http://www.mynamespace.com')
end
def test_create_unbound_ns
error = assert_raises(TypeError) do
LibXML::XML::Namespace.new(nil, 'my_namepace', 'http://www.mynamespace.com')
end
assert_equal('wrong argument type nil (expected Data)', error.to_s)
end
def test_duplicate_ns
node = LibXML::XML::Node.new('foo')
LibXML::XML::Namespace.new(node, 'myname', 'http://www.mynamespace.com')
LibXML::XML::Namespace.new(node, 'myname', 'http://www.mynamespace.com')
end
def test_eql
node = LibXML::XML::Node.new('Envelope')
assert(node.namespaces.namespace.eql?(node.namespaces.namespace))
end
def test_equal
node1 = LibXML::XML::Node.new('Envelope')
ns1 = LibXML::XML::Namespace.new(node1, 'soap', 'http://schemas.xmlsoap.org/soap/envelope/')
node2 = LibXML::XML::Node.new('Envelope')
ns2 = LibXML::XML::Namespace.new(node2, 'soap', 'http://schemas.xmlsoap.org/soap/envelope/')
assert(ns1 == ns2)
end
end
libxml-ruby-5.0.3/test/test_deprecated_require.rb 0000644 0000041 0000041 00000000564 14620142101 022210 0 ustar www-data www-data # encoding: UTF-8
require 'xml/libxml'
class TestDeprecatedRequire < Minitest::Test
def test_basic
xp = LibXML::XML::Parser.string('onetwo')
assert_instance_of(LibXML::XML::Parser, xp)
@doc = xp.parse
assert_instance_of(LibXML::XML::Document, @doc)
end
end
libxml-ruby-5.0.3/test/test_node_xlink.rb 0000644 0000041 0000041 00000001435 14620142101 020504 0 ustar www-data www-data # encoding: UTF-8
# $Id$
require_relative './test_helper'
class TC_XML_Node_XLink < Minitest::Test
def setup()
xp = LibXML::XML::Parser.string('one')
doc = xp.parse
assert_instance_of(LibXML::XML::Document, doc)
@root = doc.root
assert_instance_of(LibXML::XML::Node, @root)
end
def teardown()
@root = nil
end
def test_xml_node_xlink()
for elem in @root.find('fixnum')
assert_instance_of(LibXML::XML::Node, elem)
assert_instance_of(TrueClass, elem.xlink?)
assert_equal("simple", elem.xlink_type_name)
assert_equal(LibXML::XML::Node::XLINK_TYPE_SIMPLE, elem.xlink_type)
end
end
end
libxml-ruby-5.0.3/test/test_dtd.rb 0000644 0000041 0000041 00000010650 14620142101 017124 0 ustar www-data www-data # encoding: UTF-8
require_relative './test_helper'
class TestDtd < Minitest::Test
def setup
xp = LibXML::XML::Parser.string(<<-EOS)
Colorado
Lots of nice mountains
EOS
@doc = xp.parse
end
def teardown
@doc = nil
end
def dtd
LibXML::XML::Dtd.new(<<-EOS)
EOS
end
def test_internal_subset
xhtml_dtd = LibXML::XML::Dtd.new("-//W3C//DTD XHTML 1.0 Transitional//EN", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", nil, nil, true)
assert xhtml_dtd.name.nil?
assert_equal "-//W3C//DTD XHTML 1.0 Transitional//EN", xhtml_dtd.external_id
assert_equal "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", xhtml_dtd.uri
assert_equal "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", xhtml_dtd.system_id
xhtml_dtd = LibXML::XML::Dtd.new("-//W3C//DTD XHTML 1.0 Transitional//EN", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", "xhtml1", nil, true)
assert_equal "xhtml1", xhtml_dtd.name
assert_equal "-//W3C//DTD XHTML 1.0 Transitional//EN", xhtml_dtd.external_id
assert_equal "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", xhtml_dtd.uri
assert_equal "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", xhtml_dtd.system_id
end
def test_external_subset
xhtml_dtd = LibXML::XML::Dtd.new("-//W3C//DTD XHTML 1.0 Transitional//EN", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", nil)
assert xhtml_dtd.name.nil?
assert_equal "-//W3C//DTD XHTML 1.0 Transitional//EN", xhtml_dtd.external_id
assert_equal "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", xhtml_dtd.uri
assert_equal "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", xhtml_dtd.system_id
xhtml_dtd = LibXML::XML::Dtd.new("-//W3C//DTD XHTML 1.0 Transitional//EN", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", "xhtml1")
assert_equal "xhtml1", xhtml_dtd.name
assert_equal "-//W3C//DTD XHTML 1.0 Transitional//EN", xhtml_dtd.external_id
assert_equal "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", xhtml_dtd.uri
assert_equal "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", xhtml_dtd.system_id
end
def test_valid
assert(@doc.validate(dtd))
end
def test_node_type
assert_equal(LibXML::XML::Node::DTD_NODE, dtd.node_type)
end
def test_invalid
new_node = LibXML::XML::Node.new('invalid', 'this will mess up validation')
@doc.root << new_node
error = assert_raises(LibXML::XML::Error) do
@doc.validate(dtd)
end
# Check the error worked
refute_nil(error)
assert_kind_of(LibXML::XML::Error, error)
assert_equal("Error: No declaration for element invalid.", error.message)
assert_equal(LibXML::XML::Error::VALID, error.domain)
assert_equal(LibXML::XML::Error::DTD_UNKNOWN_ELEM, error.code)
assert_equal(LibXML::XML::Error::ERROR, error.level)
assert_nil(error.file)
assert_nil(error.line)
assert_equal('invalid', error.str1)
# Different answers across operating systems
# assert_nil(error.str2)
assert_nil(error.str3)
assert_equal(0, error.int1)
assert_equal(0, error.int2)
refute_nil(error.node)
assert_equal('invalid', error.node.name)
end
def test_external_dtd
xml = <<-EOS
T1
EOS
errors = Array.new
LibXML::XML::Error.set_handler do |error|
errors << error
end
LibXML::XML::Parser.string(xml).parse
assert_equal(0, errors.length)
errors.clear
LibXML::XML::Parser.string(xml, options: LibXML::XML::Parser::Options::DTDLOAD).parse
assert_equal(1, errors.length)
assert_equal("Warning: failed to load external entity \"test.dtd\" at :1.",
errors[0].to_s)
errors = Array.new
LibXML::XML::Parser.string(xml, :options => LibXML::XML::Parser::Options::DTDLOAD).parse
assert_equal(1, errors.length)
assert_equal("Warning: failed to load external entity \"test.dtd\" at :1.",
errors[0].to_s)
ensure
LibXML::XML::Error.reset_handler
end
end
libxml-ruby-5.0.3/test/test_node_edit.rb 0000644 0000041 0000041 00000011170 14620142101 020301 0 ustar www-data www-data # encoding: UTF-8
require_relative './test_helper'
class TestNodeEdit < Minitest::Test
def setup
xp = LibXML::XML::Parser.string('onetwothree')
@doc = xp.parse
end
def teardown
@doc = nil
end
def first_node
@doc.root.child
end
def second_node
first_node.next
end
def third_node
second_node.next
end
def test_add_next_01
first_node.next = LibXML::XML::Node.new('num', 'one-and-a-half')
assert_equal('oneone-and-a-halftwothree',
@doc.root.to_s.gsub(/\n\s*/,''))
end
def test_add_next_02
second_node.next = LibXML::XML::Node.new('num', 'two-and-a-half')
assert_equal('onetwotwo-and-a-halfthree',
@doc.root.to_s.gsub(/\n\s*/,''))
end
def test_add_next_03
third_node.next = LibXML::XML::Node.new('num', 'four')
assert_equal 'onetwothreefour',
@doc.root.to_s.gsub(/\n\s*/,'')
end
def test_add_prev_01
first_node.prev = LibXML::XML::Node.new('num', 'half')
assert_equal 'halfonetwothree',
@doc.root.to_s.gsub(/\n\s*/,'')
end
def test_add_prev_02
second_node.prev = LibXML::XML::Node.new('num', 'one-and-a-half')
assert_equal 'oneone-and-a-halftwothree',
@doc.root.to_s.gsub(/\n\s*/,'')
end
def test_add_prev_03
third_node.prev = LibXML::XML::Node.new('num', 'two-and-a-half')
assert_equal 'onetwotwo-and-a-halfthree',
@doc.root.to_s.gsub(/\n\s*/,'')
end
def test_remove_node
first_node.remove!
assert_equal('twothree',
@doc.root.to_s.gsub(/\n\s*/,''))
end
def test_remove_node_gc
xp = LibXML::XML::Parser.string('onetwothree')
doc = xp.parse
doc.root.child.remove!
GC.start
refute_nil(doc)
end
def test_remove_node_iteration
nodes = Array.new
@doc.root.each_element do |node|
if node.name == 'num'
nodes << node
node.remove!
end
end
assert_equal(3, nodes.length)
end
def test_reuse_removed_node
# Remove the node
node = @doc.root.first.remove!
refute_nil(node)
# Add it to the end of the document
@doc.root.last.next = node
assert_equal('twothreeone',
@doc.root.to_s.gsub(/\n\s*/,''))
end
def test_append_existing_node
doc = LibXML::XML::Parser.string('abfirstsecondcd').parse
node1 = doc.find_first('//two')
doc.root << node1
assert_equal('abfirstcdsecond',
doc.root.to_s)
end
def test_wrong_doc
doc1 = LibXML::XML::Parser.string('').parse
doc2 = LibXML::XML::Parser.string('').parse
node = doc1.root.child
error = assert_raises(LibXML::XML::Error) do
doc2.root << node
end
GC.start
assert_equal(' Nodes belong to different documents. You must first import the node by calling LibXML::XML::Document.import.',
error.to_s)
end
# This test is to verify that an earlier reported bug has been fixed
def test_merge
documents = []
# Read in 500 documents
500.times do
documents << LibXML::XML::Parser.string(File.read(File.join(File.dirname(__FILE__), 'model', 'merge_bug_data.xml'))).parse
end
master_doc = documents.shift
documents.each do |child_doc|
master_body = master_doc.find("//body").first
child_body = child_doc.find("//body").first
child_element = child_body.detect do |node|
node.element?
end
master_body << child_element.copy(true)
end
end
def test_append_chain
node = LibXML::XML::Node.new('foo') << LibXML::XML::Node.new('bar') << "bars contents"
assert_equal('bars contents',
node.to_s)
end
def test_set_base
@doc.root.base_uri = 'http://www.rubynet.org/'
assert_equal("\n one\n two\n three\n",
@doc.root.to_s)
end
end
libxml-ruby-5.0.3/test/test_html_parser_context.rb 0000644 0000041 0000041 00000001134 14620142101 022432 0 ustar www-data www-data # encoding: UTF-8
require_relative './test_helper'
class TestHtmlParserContext < Minitest::Test
def test_default_options
context = LibXML::XML::HTMLParser::Context.new
assert_equal(0, context.options)
end
def test_no_options
context = LibXML::XML::HTMLParser::Context.new
context.options = 0
assert_equal(0, context.options)
end
def test_options
context = LibXML::XML::HTMLParser::Context.new
context.options = LibXML::XML::HTMLParser::Options::NOERROR
assert_equal(LibXML::XML::HTMLParser::Options::NOERROR, context.options)
end
end libxml-ruby-5.0.3/test/test_document.rb 0000644 0000041 0000041 00000010421 14620142101 020163 0 ustar www-data www-data # encoding: UTF-8
require_relative './test_helper'
class TestDocument < Minitest::Test
def setup
xp = LibXML::XML::Parser.string('onetwo')
assert_instance_of(LibXML::XML::Parser, xp)
@doc = xp.parse
assert_instance_of(LibXML::XML::Document, @doc)
end
def teardown
@doc = nil
end
def test_klass
assert_instance_of(LibXML::XML::Document, @doc)
end
def test_context
context = @doc.context
assert_instance_of(LibXML::XML::XPath::Context, context)
end
def test_find
set = @doc.find('/ruby_array/fixnum')
assert_instance_of(LibXML::XML::XPath::Object, set)
assert_raises(NoMethodError) {
set.xpath
}
end
def test_compression
if LibXML::XML.enabled_zlib?
0.upto(9) do |i|
assert_equal(i, @doc.compression = i)
assert_equal(i, @doc.compression)
end
9.downto(0) do |i|
assert_equal(i, @doc.compression = i)
assert_equal(i, @doc.compression)
end
10.upto(20) do |i|
# assert_equal(9, @doc.compression = i)
assert_equal(i, @doc.compression = i) # This works around a bug in Ruby 1.8
assert_equal(9, @doc.compression)
end
-1.downto(-10) do |i|
# assert_equal(0, @doc.compression = i)
assert_equal(i, @doc.compression = i) # FIXME This bug should get fixed ASAP
assert_equal(0, @doc.compression)
end
end
end
def test_version
assert_equal('1.0', @doc.version)
doc = LibXML::XML::Document.new('6.9')
assert_equal('6.9', doc.version)
end
def test_write_root
@doc.root = LibXML::XML::Node.new('rubynet')
assert_instance_of(LibXML::XML::Node, @doc.root)
assert_instance_of(LibXML::XML::Document, @doc.root.doc)
assert_equal("\n\n",
@doc.to_s(:indent => false))
end
def test_doc_node_type
assert_equal(LibXML::XML::Node::DOCUMENT_NODE, LibXML::XML::Document.new.node_type)
end
def test_doc_node_type_name
assert_equal('document_xml', LibXML::XML::Document.new.node_type_name)
end
def test_xhtml
doc = LibXML::XML::Document.new
assert(!doc.xhtml?)
LibXML::XML::Dtd.new("-//W3C//DTD XHTML 1.0 Transitional//EN", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", nil, doc, true)
assert(doc.xhtml?)
end
def test_document_root
doc1 = LibXML::XML::Document.string("")
doc2 = LibXML::XML::Document.string("")
error = assert_raises(LibXML::XML::Error) do
doc1.root = doc2.root
end
assert_equal(" Nodes belong to different documents. You must first import the node by calling LibXML::XML::Document.import.",
error.to_s)
doc2.root << doc2.import(doc1.root)
assert_equal('', doc1.root.to_s)
assert_equal('', doc2.root.to_s(:indent => false))
assert(!doc1.root.equal?(doc2.root))
assert(doc1.root.doc != doc2.root.doc)
end
def test_import_node
doc1 = LibXML::XML::Parser.string('').parse
doc2 = LibXML::XML::Parser.string('').parse
node = doc1.root.child
error = assert_raises(LibXML::XML::Error) do
doc2.root << node
end
assert_equal(" Nodes belong to different documents. You must first import the node by calling LibXML::XML::Document.import.",
error.to_s)
doc2.root << doc2.import(node)
assert_equal("",
doc2.root.to_s(:indent => false))
end
def test_nonet
xml_string = 'onetwo'
xml = LibXML::XML::Document.string(xml_string, options: LibXML::XML::Parser::Options::NONET)
file = File.join(File.dirname(__FILE__), 'model/atom.xml')
schema_document = LibXML::XML::Document.file(file, options: LibXML::XML::Parser::Options::NONET)
end
def test_io
File.open(File.join(File.dirname(__FILE__), 'model/rubynet.xml')) do |io|
doc = LibXML::XML::Document.io(io)
assert_instance_of(LibXML::XML::Document, doc)
end
end
end
libxml-ruby-5.0.3/test/test_reader.rb 0000644 0000041 0000041 00000032410 14620142101 017611 0 ustar www-data www-data # encoding: UTF-8
require_relative './test_helper'
require 'stringio'
class TestReader < Minitest::Test
XML_FILE = File.join(File.dirname(__FILE__), 'model/atom.xml')
def verify_simple(reader)
node_types = []
# Read each node
26.times do
assert(reader.read)
node_types << reader.node_type
end
# There are no more nodes
assert(!reader.read)
# Check what was read
expected = [LibXML::XML::Reader::TYPE_PROCESSING_INSTRUCTION,
LibXML::XML::Reader::TYPE_ELEMENT,
LibXML::XML::Reader::TYPE_SIGNIFICANT_WHITESPACE,
LibXML::XML::Reader::TYPE_COMMENT,
LibXML::XML::Reader::TYPE_SIGNIFICANT_WHITESPACE,
LibXML::XML::Reader::TYPE_ELEMENT,
LibXML::XML::Reader::TYPE_SIGNIFICANT_WHITESPACE,
LibXML::XML::Reader::TYPE_ELEMENT,
LibXML::XML::Reader::TYPE_CDATA,
LibXML::XML::Reader::TYPE_END_ELEMENT,
LibXML::XML::Reader::TYPE_SIGNIFICANT_WHITESPACE,
LibXML::XML::Reader::TYPE_ELEMENT,
LibXML::XML::Reader::TYPE_SIGNIFICANT_WHITESPACE,
LibXML::XML::Reader::TYPE_ELEMENT,
LibXML::XML::Reader::TYPE_SIGNIFICANT_WHITESPACE,
LibXML::XML::Reader::TYPE_ELEMENT,
LibXML::XML::Reader::TYPE_TEXT,
LibXML::XML::Reader::TYPE_END_ELEMENT,
LibXML::XML::Reader::TYPE_SIGNIFICANT_WHITESPACE,
LibXML::XML::Reader::TYPE_END_ELEMENT,
LibXML::XML::Reader::TYPE_SIGNIFICANT_WHITESPACE,
LibXML::XML::Reader::TYPE_END_ELEMENT,
LibXML::XML::Reader::TYPE_SIGNIFICANT_WHITESPACE,
LibXML::XML::Reader::TYPE_END_ELEMENT,
LibXML::XML::Reader::TYPE_SIGNIFICANT_WHITESPACE,
LibXML::XML::Reader::TYPE_END_ELEMENT]
assert_equal(expected, node_types)
end
def test_document
reader = LibXML::XML::Reader.document(LibXML::XML::Document.file(XML_FILE))
verify_simple(reader)
end
def test_file
reader = LibXML::XML::Reader.file(XML_FILE)
verify_simple(reader)
end
def test_invalid_file
error = assert_raises(Errno::ENOENT) do
LibXML::XML::Reader.file('/does/not/exist')
end
assert_equal("No such file or directory - /does/not/exist", error.message)
end
def test_string
reader = LibXML::XML::Reader.string(File.read(XML_FILE))
verify_simple(reader)
end
def test_io
File.open(XML_FILE, 'rb') do |io|
reader = LibXML::XML::Reader.io(io)
verify_simple(reader)
end
end
def test_io_gc
# Test that the reader keeps a reference
# to the io object
file = File.open(XML_FILE, 'rb')
reader = LibXML::XML::Reader.io(file)
file = nil
GC.start
assert(reader.read)
end
def test_string_io
data = File.read(XML_FILE)
string_io = StringIO.new(data)
reader = LibXML::XML::Reader.io(string_io)
verify_simple(reader)
end
def test_error
reader = LibXML::XML::Reader.string('")
assert(parser.read)
assert_equal('foo', parser.name)
assert_equal('1', parser['x'])
assert_equal('1', parser[0])
assert_equal('2', parser['y'])
assert_equal('2', parser[1])
assert_nil(parser['z'])
assert_nil(parser[2])
end
def test_move_attr
reader = LibXML::XML::Reader.string('')
assert(reader.read) #
assert(reader.read) #
assert(reader.move_to_attribute_no(1))
assert_equal(reader.value, 'def')
assert(reader.move_to_attribute_ns('id', 'http://www.w3.org/XML/1998/namespace'))
assert_equal(reader.value, 'abc')
assert(reader.move_to_attribute('bar'))
assert_equal(reader.value, 'jkl')
# 1 in case of success, -1 in case of error, 0 if not found
assert_equal(reader.move_to_attribute_no(12), 0)
assert_equal(reader.move_to_attribute('baz'), 0)
assert_equal(reader.move_to_attribute_ns('baz', 'http://ruby/namespace'), 0)
end
def test_get_attr
reader = LibXML::XML::Reader.string('')
assert(reader.read) #
assert(reader.read) #
assert_equal(reader.get_attribute_no(1), 'def')
assert_equal(reader.get_attribute_ns('id', 'http://www.w3.org/XML/1998/namespace'), 'abc')
assert_equal(reader.get_attribute('bar'), 'jkl')
assert_nil(reader.get_attribute_no(12))
assert_nil(reader.get_attribute('baz'))
assert_nil(reader.get_attribute_ns('baz', 'http://ruby/namespace'))
end
def test_value
parser = LibXML::XML::Reader.string("123")
assert(parser.read)
assert_equal('foo', parser.name)
assert_nil(parser.value)
3.times do |i|
assert(parser.read)
assert_equal(LibXML::XML::Reader::TYPE_ELEMENT, parser.node_type)
assert_equal('bar', parser.name)
assert(parser.read)
assert_equal(LibXML::XML::Reader::TYPE_TEXT, parser.node_type)
assert_equal((i + 1).to_s, parser.value)
assert(parser.read)
assert_equal(LibXML::XML::Reader::TYPE_END_ELEMENT, parser.node_type)
end
end
def test_expand
reader = LibXML::XML::Reader.file(XML_FILE)
reader.read.to_s
reader.read
# Read a node
node = reader.expand
refute_nil(node.doc)
assert_equal('feed', node.name)
assert_equal(::Encoding::UTF_8, node.name.encoding) if defined?(::Encoding)
end
def test_expand_find
reader = LibXML::XML::Reader.file(XML_FILE)
reader.read.to_s
reader.read
# Read first node which
node = reader.expand
assert_equal('feed', node.name)
# We need to create document to use xpath
reader.doc
# Search for entries
entries = node.find('atom:entry', 'atom:http://www.w3.org/2005/Atom')
assert_equal(1, entries.length)
end
def test_expand_invalid
reader = LibXML::XML::Reader.file(XML_FILE)
# Expand a node before one has been read
node = reader.expand
assert_nil(node)
end
def test_expand_should_be_invalid
reader = LibXML::XML::Reader.file(XML_FILE)
# Read a couple of nodes
reader.read
reader.read
# Expand the node
node = reader.expand
assert_equal('feed', node.name)
# Read another node, this makes the last node invalid
reader.next
# The previous node is now invalid - this should be an error but isn't
assert_equal('feed', node.name)
end
def test_expand_incorrectly_use_returned_node
file = File.join(File.dirname(__FILE__), 'model/cwm_1_0.xml')
reader = LibXML::XML::Reader.file(file)
nodes = Array.new
while reader.read
node = reader.expand
refute_nil(node)
refute_nil(node.doc)
# NOTE - DO NOT do this in real code, these nodes are invalid after the next read. This *will* cause
# a segmentation fault next time the garbage collector runs. The reason is the parent node will be
# called in the mark phase, but its underlying xml node will be gone. Same goes for calling children,
# attributes, etc. You must let go of the expanded node *before* calling xml reader again and
# call the garbage collector to be safe.
#refute_nil(node.parent)
nodes << node
end
assert(true)
end
def test_mode
reader = LibXML::XML::Reader.string('')
assert_equal(LibXML::XML::Reader::MODE_INITIAL, reader.read_state)
reader.read
assert_equal(LibXML::XML::Reader::MODE_EOF, reader.read_state)
end
def test_bytes_consumed
ending_are_rn = File.binread(XML_FILE).include? "\r\n"
reader = LibXML::XML::Reader.file(XML_FILE)
reader.read
assert_equal(ending_are_rn ? 428 : 416, reader.byte_consumed)
end
def test_node
reader = LibXML::XML::Reader.file(XML_FILE)
# first try to get a node
assert_nil(reader.node)
reader.read
assert_instance_of(LibXML::XML::Node, reader.node)
end
def test_base_uri
# UTF8:
# ö - c3 b6 in hex, \303\266 in octal
# ü - c3 bc in hex, \303\274 in octal
xml = "\n An American heavy metal band formed in Los Angeles, California in 1981.\n British heavy metal band formed in 1975.\n"
reader = LibXML::XML::Reader.string(xml, :base_uri => "http://libxml.rubyforge.org")
reader.read
assert_equal(reader.base_uri, "http://libxml.rubyforge.org")
assert_equal(::Encoding::UTF_8, reader.base_uri.encoding) if defined?(::Encoding)
end
def test_options
xml = <<-EOS
]>
&foo;
EOS
# Parse normally
reader = LibXML::XML::Reader.string(xml)
reader.read # foo
reader.read # test
reader.read # text
reader.read # cdata
reader.read # cdata-section
assert_equal(LibXML::XML::Node::CDATA_SECTION_NODE, reader.node_type)
# Convert cdata section to text
reader = LibXML::XML::Reader.string(xml, :options => LibXML::XML::Parser::Options::NOCDATA)
reader.read # foo
reader.read # test
reader.read # text
reader.read # cdata
reader.read # cdata-section
assert_equal(LibXML::XML::Node::TEXT_NODE, reader.node_type)
end
def test_encoding
# ISO_8859_1:
# ö - f6 in hex, \366 in octal
# ü - fc in hex, \374 in octal
xml = "\n An American heavy metal band formed in Los Angeles, California in 1981.\n British heavy metal band formed in 1975.\n"
reader = LibXML::XML::Reader.string(xml, :encoding => LibXML::XML::Encoding::ISO_8859_1)
reader.read
assert_equal(Encoding::ISO8859_1, reader.read_outer_xml.encoding)
assert_equal(Encoding::ISO8859_1, reader.read_inner_xml.encoding)
assert_equal(Encoding::ISO8859_1, reader.read_string.encoding)
assert_equal("\n An American heavy metal band formed in Los Angeles, California in 1981.\n British heavy metal band formed in 1975.\n".force_encoding(Encoding::ISO8859_1),
reader.read_outer_xml)
assert_equal("\n An American heavy metal band formed in Los Angeles, California in 1981.\n British heavy metal band formed in 1975.\n".force_encoding(Encoding::ISO8859_1),
reader.read_inner_xml)
assert_equal("\n An American heavy metal band formed in Los Angeles, California in 1981.\n British heavy metal band formed in 1975.\n".force_encoding(Encoding::ISO8859_1),
reader.read_string)
end
def test_invalid_encoding
# ISO_8859_1:
# ö - f6 in hex, \366 in octal
# ü - fc in hex, \374 in octal
xml = "\n An American heavy metal band formed in Los Angeles, California in 1981.\n British heavy metal band formed in 1975.\n"
reader = LibXML::XML::Reader.string(xml)
error = assert_raises(LibXML::XML::Error) do
reader.read
end
assert_equal("Fatal error: Input is not proper UTF-8, indicate encoding !\nBytes: 0xF6 0x74 0x6C 0x65 at :2.",
error.to_s)
end
def test_file_encoding
reader = LibXML::XML::Reader.file(XML_FILE)
reader.read
assert_equal(LibXML::XML::Encoding::UTF_8, reader.encoding)
assert_equal(Encoding::UTF_8, reader.value.encoding)
end
def test_string_encoding
# ISO_8859_1:
# ö - f6 in hex, \366 in octal
# ü - fc in hex, \374 in octal
xml = "\n An American heavy metal band formed in Los Angeles, California in 1981.\n British heavy metal band formed in 1975.\n"
reader = LibXML::XML::Reader.string(xml, :encoding => LibXML::XML::Encoding::ISO_8859_1)
reader.read
encoding = windows? ? LibXML::XML::Encoding::ISO_8859_1 : LibXML::XML::Encoding::NONE
assert_equal(reader.encoding, encoding)
end
end
libxml-ruby-5.0.3/test/test_node_text.rb 0000644 0000041 0000041 00000004030 14620142101 020335 0 ustar www-data www-data # encoding: UTF-8
require_relative './test_helper'
class TestTextNode < Minitest::Test
def test_content
node = LibXML::XML::Node.new_text('testdata')
assert_instance_of(LibXML::XML::Node, node)
assert_equal('testdata', node.content)
end
def test_invalid_content
error = assert_raises(TypeError) do
LibXML::XML::Node.new_text(nil)
end
assert_equal('wrong argument type nil (expected String)', error.to_s)
end
# We use the same facility that libXSLT does here to disable output escaping.
# This lets you specify that the node's content should be rendered unaltered
# whenever it is being output. This is useful for things like