class HTree::XMLDecl
Attributes
encoding[R]
standalone[R]
version[R]
Public Class Methods
new(version, encoding=nil, standalone=nil)
click to toggle source
# File htree/leaf.rb, line 6 def initialize(version, encoding=nil, standalone=nil) init_raw_string if /\A[a-zA-Z0-9_.:-]+\z/ !~ version raise HTree::Error, "invalid version in XML declaration: #{version.inspect}" end if encoding && /\A[A-Za-z][A-Za-z0-9._-]*\z/ !~ encoding raise HTree::Error, "invalid encoding in XML declaration: #{encoding.inspect}" end unless standalone == nil || standalone == true || standalone == false raise HTree::Error, "invalid standalone document declaration in XML declaration: #{standalone.inspect}" end @version = version @encoding = encoding @standalone = standalone end
parse(raw_string)
click to toggle source
# File htree/parse.rb, line 351 def XMLDecl.parse(raw_string) unless /\A#{Pat::XmlDecl_C}\z/o =~ raw_string raise HTree::Error, "cannot recognize as XML declaration: #{raw_string.inspect}" end version = $1 || $2 encoding = $3 || $4 case $5 || $6 when 'yes' standalone = true when 'no' standalone = false else standalone = nil end result = XMLDecl.new(version, encoding, standalone) result.raw_string = raw_string result end