Class: VCDOM::Document

Inherits:
Node
  • Object
show all
Includes:
Parent
Defined in:
lib/vcdom/document.rb

Instance Method Summary collapse

Constructor Details

#initializeDocument

Returns a new instance of Document.



17
18
19
20
# File 'lib/vcdom/document.rb', line 17

def initialize()
  initialize_parent()
  super( nil )
end

Instance Method Details

#append_child(new_child) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/vcdom/document.rb', line 26

def append_child( new_child )
  # ノードのタイプチェックなど
  if not new_child.is_a? Node then
    raise ArgumentError.new( "the argument [#{new_child.inspect}] is not an object of the expected class." )
  end
  # Element (maximum of one), ProcessingInstruction, Comment, DocumentType (maximum of one) 
  case new_child.node_type
    when ELEMENT_NODE then
      # 既に追加されてるかどうかのチェック
      if @document_element.nil? then
        @document_element = new_child
      else
        raise "HIERARCHY_REQUEST_ERR"
      end
    when DOCUMENT_TYPE_NODE then
      # 既に追加されてるかどうかのチェック
    when PROCESSING_INSTRUCTION_NODE, COMMENT_NODE then
      # OK
    else
      # ERROR
      raise "ERROR"
  end
  _append_child( new_child )
end

#create_attribute(name) ⇒ Object



83
84
85
86
87
88
89
90
91
# File 'lib/vcdom/document.rb', line 83

def create_attribute( name )
  attr = nil
  if name.is_a? String then
    attr = Attr._new( self, name.intern )
  else
    raise ArgumentError.new( "the argument [#{new_child.inspect}] is not an object of the expected class." )
  end
  attr
end

#create_attribute_ns(namespace_uri, qualified_name) ⇒ Object



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/vcdom/document.rb', line 93

def create_attribute_ns( namespace_uri, qualified_name )
  attr = nil
  if namespace_uri.is_a? String then
    namespace_uri = namespace_uri.intern
  elsif not namespace_uri.nil? then
    raise ArgumentError.new( "the argument *namespace_uri* must be a String object or nil." )
  end
  if qualified_name.is_a? String then
    name_parts = qualified_name.split /:/
    if name_parts.length == 1 then
      attr = AttrNS._new( self, namespace_uri, nil, name_parts[0].intern )
    elsif name_parts.length == 2 then
      attr = AttrNS._new( self, namespace_uri, name_parts[0].intern, name_parts[1].intern )
    else
      raise "ERROR"
    end
  else
    raise "ERROR"
  end
  attr
end

#create_element(tag_name) ⇒ Object



51
52
53
54
55
56
57
58
59
# File 'lib/vcdom/document.rb', line 51

def create_element( tag_name )
  elem = nil
  if tag_name.is_a? String then
    elem = Element._new( self, tag_name.intern )
  else
    raise "ERROR"
  end
  elem
end

#create_element_ns(namespace_uri, qualified_name) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/vcdom/document.rb', line 61

def create_element_ns( namespace_uri, qualified_name )
  elem = nil
  if namespace_uri.is_a? String then
    namespace_uri = namespace_uri.intern
  elsif not namespace_uri.nil? then
    raise "ERROR"
  end
  if qualified_name.is_a? String then
    name_parts = qualified_name.split /:/
    if name_parts.length == 1 then
      elem = ElementNS._new( self, namespace_uri, nil, name_parts[0].intern )
    elsif name_parts.length == 2 then
      elem = ElementNS._new( self, namespace_uri, name_parts[0].intern, name_parts[1].intern )
    else
      raise "ERROR"
    end
  else
    raise "ERROR"
  end
  elem
end

#create_text_node(data) ⇒ Object



115
116
117
118
119
120
121
122
123
# File 'lib/vcdom/document.rb', line 115

def create_text_node( data )
  node = nil
  if data.is_a? String then
    node = Text._new( self, data.intern )
  else
    raise ArgumentError.new( "the argument [#{data.inspect}] is not an object of the expected class. the class : #{data.class}" )
  end
  node
end

#node_typeObject



22
23
24
# File 'lib/vcdom/document.rb', line 22

def node_type
  DOCUMENT_NODE
end