Hpricot

Permission is granted for use, copying, modification, distribution,
and distribution of modified versions of this work as long as the
above copyright notice is included.

++


Public Class Methods

XML(input = nil, opts = {}, &blk) click to toggle source

Hpricot::XML parses input, disregarding all the HTML rules and returning a document tree.

# File lib/hpricot/parse.rb, line 20
def Hpricot.XML(input = nil, opts = {}, &blk)
  opts.merge! :xml => true
  make(input, opts, &blk)
end
build(ele = Doc.new, assigns = {}, &blk) click to toggle source
# File lib/hpricot/builder.rb, line 15
def self.build(ele = Doc.new, assigns = {}, &blk)
  ele.extend Builder
  assigns.each do |k, v|
    ele.instance_variable_set("@#{k}", v)
  end
  ele.instance_eval(&blk)
  ele
end
parse(input = nil, opts = {}, &blk) click to toggle source

Hpricot.parse parses input and return a document tree. represented by Hpricot::Doc.

# File lib/hpricot/parse.rb, line 14
def Hpricot.parse(input = nil, opts = {}, &blk)
  make(input, opts, &blk)
end
uxs(str) click to toggle source

XML unescape

# File lib/hpricot/builder.rb, line 8
def self.uxs(str)
  str.to_s.
      gsub(/\&(\w+);/) { [NamedCharacters[$1] || 63].pack("U*") }. # 63 = ?? (query char)
      gsub(/\&\#(\d+);/) { [$1.to_i].pack("U*") }.
      gsub(/\&\#x([0-9a-fA-F]+);/) { [$1.to_i(16)].pack("U*") }
end
xchr(str) click to toggle source

XML escaped version of chr

# File lib/hpricot/xchar.rb, line 70
def xchr(str)
  n = XChar::CP1252[str] || str
  case n when *XChar::VALID
    XChar::PREDEFINED[n] or (n<128 ? n.chr : "&##{n};")
  else
    '*'
  end
end
xs(str) click to toggle source

XML escaped version of to_s

# File lib/hpricot/xchar.rb, line 80
def xs(str)
  str.to_s.unpack('U*').map {|n| xchr(n)}.join # ASCII, UTF-8
rescue
  str.to_s.unpack('C*').map {|n| xchr(n)}.join # ISO-8859-1, WIN-1252
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.