class REXML::DocType
表示 XML DOCTYPE 声明;即 <!DOCTYPE … > 的内容。DOCTYPE 可用于声明文档的 DTD
,也可用于声明文档中使用的实体。
常量
- DEFAULT_ENTITIES
- PUBLIC
- START
- STOP
- SYSTEM
属性
entities[R]
name 是 doctype 的名称, external_id
是引用的 DTD
(如果给定)。
external_id[R]
name 是 doctype 的名称, external_id
是引用的 DTD
(如果给定)。
name[R]
name 是 doctype 的名称, external_id
是引用的 DTD
(如果给定)。
namespaces[R]
name 是 doctype 的名称, external_id
是引用的 DTD
(如果给定)。
公共类方法
new( first, parent=nil ) 点击切换源代码
构造函数
dt = DocType.new( 'foo', '-//I/Hate/External/IDs' ) # <!DOCTYPE foo '-//I/Hate/External/IDs'> dt = DocType.new( doctype_to_clone ) # Incomplete. Shallow clone of doctype
注意
,构造函数
Doctype.new( Source.new( "<!DOCTYPE foo 'bar'>" ) )
是已弃用的。不要使用它。它很可能会消失。
调用超类方法
# File rexml-3.4.0/lib/rexml/doctype.rb, line 80 def initialize( first, parent=nil ) @entities = DEFAULT_ENTITIES @long_name = @uri = nil if first.kind_of? String super() @name = first @external_id = parent elsif first.kind_of? DocType super( parent ) @name = first.name @external_id = first.external_id @long_name = first.instance_variable_get(:@long_name) @uri = first.instance_variable_get(:@uri) elsif first.kind_of? Array super( parent ) @name = first[0] @external_id = first[1] @long_name = first[2] @uri = first[3] elsif first.kind_of? Source super( parent ) parser = Parsers::BaseParser.new( first ) event = parser.pull if event[0] == :start_doctype @name, @external_id, @long_name, @uri, = event[1..-1] end else super() end end
公共实例方法
add(child) 点击切换源代码
调用超类方法
# File rexml-3.4.0/lib/rexml/doctype.rb, line 185 def add child super(child) @entities = DEFAULT_ENTITIES.clone if @entities == DEFAULT_ENTITIES @entities[ child.name ] = child if child.kind_of? Entity end
attribute_of(element, attribute) 点击切换源代码
# File rexml-3.4.0/lib/rexml/doctype.rb, line 125 def attribute_of element, attribute att_decl = find do |child| child.kind_of? AttlistDecl and child.element_name == element and child.include? attribute end return nil unless att_decl att_decl[attribute] end
attributes_of(element) 点击切换源代码
# File rexml-3.4.0/lib/rexml/doctype.rb, line 115 def attributes_of element rv = [] each do |child| child.each do |key,val| rv << Attribute.new(key,val) end if child.kind_of? AttlistDecl and child.element_name == element end rv end
clone() 点击切换源代码
# File rexml-3.4.0/lib/rexml/doctype.rb, line 135 def clone DocType.new self end
context() 点击切换源代码
# File rexml-3.4.0/lib/rexml/doctype.rb, line 173 def context if @parent @parent.context else nil end end
entity( name ) 点击切换源代码
# File rexml-3.4.0/lib/rexml/doctype.rb, line 181 def entity( name ) @entities[name].unnormalized if @entities[name] end
node_type() 点击切换源代码
# File rexml-3.4.0/lib/rexml/doctype.rb, line 111 def node_type :doctype end
notation(name) 点击切换源代码
检索命名的表示法。只能检索在内部 DTD
子集中声明的表示法。
由 Henrik Martensson 贡献的方法
# File rexml-3.4.0/lib/rexml/doctype.rb, line 229 def notation(name) notations.find { |notation_decl| notation_decl.name == name } end
notations() 点击切换源代码
public() 点击切换源代码
此方法检索标识文档 DTD
的公共标识符。
由 Henrik Martensson 贡献的方法
# File rexml-3.4.0/lib/rexml/doctype.rb, line 195 def public case @external_id when "SYSTEM" nil when "PUBLIC" @long_name end end
system() 点击切换源代码
此方法检索标识文档 DTD
的系统标识符。
由 Henrik Martensson 贡献的方法
# File rexml-3.4.0/lib/rexml/doctype.rb, line 207 def system case @external_id when "SYSTEM" @long_name when "PUBLIC" @uri.kind_of?(String) ? @uri : nil end end
write( output, indent=0, transitive=false, ie_hack=false ) 点击切换源代码
- output
-
将字符串写入何处
- indent
-
一个整数。如果为 -1,则不使用缩进;否则,缩进将为此数字的空格数,并且子元素将缩进额外的量。
- transitive
-
忽略
- ie_hack
-
忽略
# File rexml-3.4.0/lib/rexml/doctype.rb, line 149 def write( output, indent=0, transitive=false, ie_hack=false ) f = REXML::Formatters::Default.new indent( output, indent ) output << START output << ' ' output << @name if @external_id reference_writer = ReferenceWriter.new(@external_id, @long_name, @uri, context) reference_writer.write(output) end unless @children.empty? output << ' [' @children.each { |child| output << "\n" f.write( child, output ) } output << "\n]" end output << STOP end