Module: Hpricot

Module | Hpricot
In: | lib/hpricot/tags.rb lib/hpricot/builder.rb lib/hpricot/traverse.rb lib/hpricot/elements.rb lib/hpricot/modules.rb lib/hpricot/inspect.rb lib/hpricot/tag.rb lib/hpricot/blankslate.rb lib/hpricot/xchar.rb lib/hpricot/htmlinfo.rb lib/hpricot/parse.rb

### Methods

XML build parse uxs uxs xchr xs

### Classes and Modules

Module Hpricot::Builder
Module Hpricot::Container
Module Hpricot::Doc
Module Hpricot::Elem
Module Hpricot::Leaf
Module Hpricot::Node
Module Hpricot::Traverse
Class Hpricot::BlankSlate
Class Hpricot::BogusETag
Class Hpricot::CData
Class Hpricot::Comment
Class Hpricot::Context
Class Hpricot::CssProxy
Class Hpricot::Doc
Class Hpricot::DocType
Class Hpricot::ETag
Class Hpricot::Elem
Class Hpricot::Elements
Class Hpricot::EncodingError
Class Hpricot::Error
Class Hpricot::Name
Class Hpricot::ProcIns
Class Hpricot::Text
Class Hpricot::XHTMLStrict
Class Hpricot::XHTMLTransitional
Class Hpricot::XMLDecl

### Constants

FORM_TAGS | = | [ :form, :input, :select, :textarea ]
SELF_CLOSING_TAGS | = | [ :base, :meta, :link, :hr, :br, :param, :img, :area, :input, :col ]
AttrCore | = | [:id, :class, :style, :title] |  | Common sets of attributes.
AttrI18n | = | [:lang, 'xml:lang'.intern, :dir]
AttrEvents | = | [:onclick, :ondblclick, :onmousedown, :onmouseup, :onmouseover, :onmousemove, :onmouseout, :onkeypress, :onkeydown, :onkeyup]
AttrFocus | = | [:accesskey, :tabindex, :onfocus, :onblur]
AttrHAlign | = | [:align, :char, :charoff]
AttrVAlign | = | [:valign]
Attrs | = | AttrCore + AttrI18n + AttrEvents

### Public Class methods

XML(input = nil, opts = {}, &blk)

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

[Source]

    # 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)

[Source]

    # File lib/hpricot/builder.rb, line 14
      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)

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

[Source]

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

uxs(str)

XML unescape

[Source]

    # File lib/hpricot/xchar.rb, line 87
        def uxs(str)
          str.to_s.
              gsub(/\&\w+;/) { |x| (XChar::PREDEFINED_U[x] || ??).chr }.
              gsub(/\&\#(\d+);/) { [$1.to_i].pack("U*") }
        end

uxs(str)

XML unescape

[Source]

    # File lib/hpricot/builder.rb, line 8
      def self.uxs(str)
        str.to_s.
            gsub(/\&(\w+);/) { [NamedCharacters[$1] || ??].pack("U*") }.
            gsub(/\&\#(\d+);/) { [$1.to_i].pack("U*") }
      end

xchr(str)

XML escaped version of chr

[Source]

    # 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)

XML escaped version of to_s

[Source]

    # 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]