Skip to content

Commit

Permalink
Initial import from libxml-ruby-0.9.9.tgz
Browse files Browse the repository at this point in the history
  • Loading branch information
tadman committed Mar 7, 2009
0 parents commit 8dcd1da
Show file tree
Hide file tree
Showing 165 changed files with 22,198 additions and 0 deletions.
434 changes: 434 additions & 0 deletions CHANGES

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions LICENSE
@@ -0,0 +1,22 @@
Copyright (c) 2008-2009 Charlie Savage and contributors
Copyright (c) 2002-2007 Sean Chittenden and contributors
Copyright (c) 2001 Wai-Sun "Squidster" Chia

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

161 changes: 161 additions & 0 deletions README
@@ -0,0 +1,161 @@
= 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 1.8.4 or higher. It is dependent on
the following libraries to function properly:

* libm (math routines: very standard)
* libz (zlib)
* libiconv
* libxml2

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 Windows specific RubyGem which
includes an already built extension.

== INSTALLATION
The easiest way to install libxml-ruby is via Ruby Gems. To install:

<tt>gem install libxml-ruby</tt>

If you are running Windows, make sure to install the Win32 RubyGem
which includes an already built binary file. The binary is built
against libxml2 version 2.7.2 and iconv version 1.11. Both of these
are also included as pre-built binaries, and should be put either in
the libxml/lib directory or on the Windows path. Due to a bug
in ruby-gems, you cannot install the gem to a path that contains
spaces (see http://rubyforge.org/tracker/?func=detail&aid=23003&group_id=126&atid=577).

The Windows binaries are built with MingW and include libxml-ruby,
libxml2 and iconv. The gem also includes a Microsoft VC++ 2008
solution. If you wish to run a debug version of libxml-ruby on
Windows, then it is highly recommended you use VC++.

== 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 choosen 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 a 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 which is available at
http://rubyforge.org/projects/libxsl/.

== Usage
For in-depth information about using libxml-ruby please refer
to its online Rdoc documentation.

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 you own work and include LibXML into it.
For example:

require 'libxml'

mdoule 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.

== 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 provided via rdoc. To generate the documentation,
run the the command 'rake doc'. libxml-ruby's online documentation
is generated using Hanna. To use hanna:

gem install mislav-hanna
rake rdoc RDOCOPT="-S -T hanna"

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 from
RubyForge (http://rdoc.rubyforge.org/). 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 uby/lib/ruby/1.8/rdoc to
ruby/lib/ruby/1.8/rdoc_old.

== Support

If you have any questions about using libxml-ruby, please send them to
libxml-devel@rubyforge.org. If you have found any bugs in libxml-devel,
or have developed new patches, please submit them to Ruby Forge at
http://rubyforge.org/tracker/?group_id=494.

== License
See LICENSE for license information.
189 changes: 189 additions & 0 deletions Rakefile
@@ -0,0 +1,189 @@
#!/usr/bin/env ruby

# Be sure to set ENV['RUBYFORGE_USERNAME'] to use publish.

require 'rubygems'
require 'rake/gempackagetask'
require 'rake/rdoctask'
require 'rake/testtask'
require 'date'


# ------- Default Package ----------
FILES = FileList[
'Rakefile',
'CHANGES',
'LICENSE',
'README',
'setup.rb',
'doc/**/*',
'ext/libxml/*',
'ext/mingw/Rakefile',
'ext/mingw/build.rake',
'ext/vc/*.sln',
'ext/vc/*.vcproj',
'lib/**/*',
'benchmark/**/*',
'test/**/*'
]

# Default GEM Specification
default_spec = Gem::Specification.new do |spec|
spec.name = "libxml-ruby"

spec.homepage = "http://libxml.rubyforge.org/"
spec.summary = "Ruby libxml bindings"
spec.description = <<-EOF
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.
EOF

# Determine the current version of the software
spec.version =
if File.read('ext/libxml/ruby_xml_version.h') =~ /\s*RUBY_LIBXML_VERSION\s*['"](\d.+)['"]/
CURRENT_VERSION = $1
else
CURRENT_VERSION = "0.0.0"
end

spec.author = "Charlie Savage"
spec.email = "libxml-devel@rubyforge.org"
spec.platform = Gem::Platform::RUBY
spec.require_paths = ["lib", "ext/libxml"]
spec.bindir = "bin"
spec.extensions = ["ext/libxml/extconf.rb"]
spec.files = FILES.to_a
spec.test_files = Dir.glob("test/tc_*.rb")

spec.required_ruby_version = '>= 1.8.4'
spec.date = DateTime.now
spec.rubyforge_project = 'libxml'

spec.has_rdoc = true
end

# Rake task to build the default package
Rake::GemPackageTask.new(default_spec) do |pkg|
pkg.package_dir = 'admin/pkg'
pkg.need_tar = true
end


# ------- Windows GEM ----------
if RUBY_PLATFORM.match(/win32/)
binaries = (FileList['ext/mingw/*.so',
'ext/mingw/*.dll*'])

# Windows specification
win_spec = default_spec.clone
win_spec.extensions = ['ext/mingw/Rakefile']
win_spec.platform = Gem::Platform::CURRENT
win_spec.files += binaries.to_a

# Rake task to build the windows package
Rake::GemPackageTask.new(win_spec) do |pkg|
pkg.package_dir = 'admin/pkg'
pkg.need_tar = false
end
end

# --------- RDoc Documentation ---------
desc "Generate rdoc documentation"
Rake::RDocTask.new("rdoc") do |rdoc|
rdoc.rdoc_dir = 'doc/rdoc'
rdoc.title = "LibXML"
# Show source inline with line numbers
rdoc.options << "--line-numbers"
# Make the readme file the start page for the generated html
rdoc.options << '--main' << 'README'
rdoc.rdoc_files.include('doc/*.rdoc',
'ext/**/*.c',
'lib/**/*.rb',
'CHANGES',
'README',
'LICENSE')
end

Rake::TestTask.new do |t|
t.libs << "test"
t.libs << "lib"
t.libs << "ext/libxml"
end

if not RUBY_PLATFORM.match(/mswin32/i)
Rake::Task[:test].prerequisites << :extensions
end

task :default => :package
task :build => :extensions
task :extension => :build

ext = Config::CONFIG["DLEXT"]
task :extensions => ["ext/libxml/libxml_ruby.#{ext}"]
file "ext/libxml/libxml_ruby.#{ext}" =>
["ext/libxml/Makefile"] + FileList["ext/libxml/*.{c,h}"].to_a do |t|
Dir.chdir("ext/libxml") { sh "make" }
end

namespace :extensions do
task :clean do
Dir.chdir("ext/libxml") do
sh "rm -f Makefile"
sh "rm -f *.{o,so,bundle,log}"
end
end
end

file "ext/libxml/Makefile" => ["ext/libxml/extconf.rb"] do
command = ["ruby"] + $:.map{|dir| "-I#{File.expand_path dir}"} + ["extconf.rb"]
Dir.chdir("ext/libxml") { sh(*command) }
end

# --------- Publish Website to Rubyforge ---------
desc "publish website (uses rsync)"
task :publish => [:publish_website, :publish_rdoc]

task :publish_website do
unixname = 'libxml'
username = ENV['RUBYFORGE_USERNAME']

dir = 'admin/web'
url = "#{username}@rubyforge.org:/var/www/gforge-projects/#{unixname}"

dir = dir.chomp('/') + '/'

# Using commandline filter options didn't seem to work, so
# I opted for creating an .rsync_filter file for all cases.

protect = %w{usage statcvs statsvn robot.txt wiki}
exclude = %w{.svn}

rsync_file = File.join(dir,'.rsync-filter')
unless File.file?(rsync_file)
File.open(rsync_file, 'w') do |f|
exclude.each{|e| f << "- #{e}\n"}
protect.each{|e| f << "P #{e}\n"}
end
end

# maybe -p ?
cmd = "rsync -rLvz --delete-after --filter='dir-merge #{rsync_file}' #{dir} #{url}"
sh cmd
end

task :publish_rdoc do
unixname = 'libxml'
username = ENV['RUBYFORGE_USERNAME']

dir = 'doc/rdoc'
url = "#{username}@rubyforge.org:/var/www/gforge-projects/#{unixname}/rdoc"

dir = dir.chomp('/') + '/'

# maybe -p ?
cmd = "rsync -rLvz --delete-after #{dir} #{url}"
sh cmd
end

0 comments on commit 8dcd1da

Please sign in to comment.