Class: VCDOM::Document

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

Instance Method Summary collapse

Constructor Details

#initializeDocument

:nodoc:



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

def initialize() # :nodoc:
  initialize_parent()
  super( nil )
end

Instance Method Details

#append_child(new_child) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/vcdom/document.rb', line 38

def append_child( new_child )
  # Check the arg type
  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
      # is there document_element already?
      if @document_element.nil? then
        @document_element = new_child
      else
        raise "HIERARCHY_REQUEST_ERR"
      end
    when DOCUMENT_TYPE_NODE then
      # is there document_type already?
    when PROCESSING_INSTRUCTION_NODE, COMMENT_NODE then
      # OK
    else
      # ERROR
      raise "ERROR : new_child.node_type = #{new_child.node_type}"
  end
  _append_child( new_child )
end

#create_attribute(name) ⇒ Object



102
103
104
105
106
107
108
109
110
# File 'lib/vcdom/document.rb', line 102

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



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/vcdom/document.rb', line 112

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



70
71
72
73
74
75
76
77
78
# File 'lib/vcdom/document.rb', line 70

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



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/vcdom/document.rb', line 80

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



134
135
136
137
138
139
# File 'lib/vcdom/document.rb', line 134

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

#document_elementObject



25
26
27
# File 'lib/vcdom/document.rb', line 25

def document_element
  @document_element
end

#node_typeObject



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

def node_type
  DOCUMENT_NODE
end

#remove_child(old_child) ⇒ Object



62
63
64
65
66
67
68
# File 'lib/vcdom/document.rb', line 62

def remove_child( old_child )
  old_child = super( old_child )
  if old_child.equal? @document_element then
    @document_element = nil
  end
  return old_child
end

#text_contentObject

always nil



30
31
32
# File 'lib/vcdom/document.rb', line 30

def text_content
  nil
end

#text_content=(val) ⇒ Object

no effect



35
36
# File 'lib/vcdom/document.rb', line 35

def text_content=( val )
end