| Class | REXML::DocType |
| In: |
|
| Parent: | Parent |
Methods
Included Modules
Constants
| START | = | "<!DOCTYPE" |
| STOP | = | ">" |
| SYSTEM | = | "SYSTEM" |
| PUBLIC | = | "PUBLIC" |
| DEFAULT_ENTITIES | = | { 'gt'=>EntityConst::GT, 'lt'=>EntityConst::LT, 'quot'=>EntityConst::QUOT, "apos"=>EntityConst::APOS |
Attributes
| entities | [R] | name is the name of the doctype external_id is the referenced DTD, if given |
| external_id | [R] | name is the name of the doctype external_id is the referenced DTD, if given |
| name | [R] | name is the name of the doctype external_id is the referenced DTD, if given |
| namespaces | [R] | name is the name of the doctype external_id is the referenced DTD, if given |
Public Class methods
Constructor
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
Note that the constructor:
Doctype.new( Source.new( "<!DOCTYPE foo 'bar'>" ) )
is deprecated. Do not use it. It will probably disappear.
41: def initialize( first, parent=nil ) 42: @entities = DEFAULT_ENTITIES 43: @long_name = @uri = nil 44: if first.kind_of? String 45: super() 46: @name = first 47: @external_id = parent 48: elsif first.kind_of? DocType 49: super( parent ) 50: @name = first.name 51: @external_id = first.external_id 52: elsif first.kind_of? Array 53: super( parent ) 54: @name = first[0] 55: @external_id = first[1] 56: @long_name = first[2] 57: @uri = first[3] 58: elsif first.kind_of? Source 59: super( parent ) 60: parser = Parsers::BaseParser.new( first ) 61: event = parser.pull 62: if event[0] == :start_doctype 63: @name, @external_id, @long_name, @uri, = event[1..-1] 64: end 65: else 66: super() 67: end 68: end
Public Instance methods
147: def add child 148: super(child) 149: @entities = DEFAULT_ENTITIES.clone if @entities == DEFAULT_ENTITIES 150: @entities[ child.name ] = child if child.kind_of? Entity 151: end
84: def attribute_of element, attribute 85: att_decl = find do |child| 86: child.kind_of? AttlistDecl and 87: child.element_name == element and 88: child.include? attribute 89: end 90: return nil unless att_decl 91: att_decl[attribute] 92: end
74: def attributes_of element 75: rv = [] 76: each do |child| 77: child.each do |key,val| 78: rv << Attribute.new(key,val) 79: end if child.kind_of? AttlistDecl and child.element_name == element 80: end 81: rv 82: end
| output: | Where to write the string |
| indent: | An integer. If -1, no indenting will be used; otherwise, the indentation will be this number of spaces, and children will be indented an additional amount. |
| transitive: | If transitive is true and indent is >= 0, then the output will be pretty-printed in such a way that the added whitespace does not affect the absolute value of the document — that is, it leaves the value and number of Text nodes in the document unchanged. |
| ie_hack: | Internet Explorer is the worst piece of crap to have ever been written, with the possible exception of Windows itself. Since IE is unable to parse proper XML, we have to provide a hack to generate XML that IE’s limited abilities can handle. This hack inserts a space before the /> on empty tags. |
116: def write( output, indent=0, transitive=false, ie_hack=false ) 117: indent( output, indent ) 118: output << START 119: output << ' ' 120: output << @name 121: output << " #@external_id" if @external_id 122: output << " #@long_name" if @long_name 123: output << " #@uri" if @uri 124: unless @children.empty? 125: next_indent = indent + 1 126: output << ' [' 127: child = nil # speed 128: @children.each { |child| 129: output << "\n" 130: child.write( output, next_indent ) 131: } 132: output << "\n" 133: #output << ' '*next_indent 134: output << "]" 135: end 136: output << STOP 137: end