Class: VCDOM::MiniDOM::NamedNodeMapAttr

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/vcdom/minidom/named_node_map_attr.rb

Instance Method Summary collapse

Constructor Details

#initialize(array, element) ⇒ NamedNodeMapAttr

Returns a new instance of NamedNodeMapAttr.



270
271
272
273
# File 'lib/vcdom/minidom/named_node_map_attr.rb', line 270

def initialize( array, element )
  @nodes = array
  @owner_element = element
end

Instance Method Details

#eachObject

独自拡張 =====


264
265
266
267
268
# File 'lib/vcdom/minidom/named_node_map_attr.rb', line 264

def each
  @nodes.each do |item|
    yield( item )
  end
end

#get_named_item(name) ⇒ Object

getNamedItem

Retrieves a node specified by name.

Parameters
  name of type DOMString
    The nodeName of a node to retrieve.
Return Value
  Node
    A Node (of any type) with the specified nodeName, or null if it does not identify any node in this map.
No Exceptions


47
48
49
# File 'lib/vcdom/minidom/named_node_map_attr.rb', line 47

def get_named_item( name )
  return @owner_element.get_attribute_node( name )
end

#get_named_item_ns(namespace_uri, local_name) ⇒ Object

getNamedItemNS introduced in DOM Level 2

Retrieves a node specified by local name and namespace URI.
Per [XML Namespaces], applications must use the value null 
as the namespaceURI parameter for methods if they wish to have no namespace.

Parameters
  namespaceURI of type DOMString
    The namespace URI of the node to retrieve.
  localName of type DOMString
    The local name of the node to retrieve.
Return Value
  Node
    A Node (of any type) with the specified local name and namespace URI, or null 
    if they do not identify any node in this map.
Exceptions
  DOMException
    NOT_SUPPORTED_ERR: May be raised if the implementation does not support the feature "XML" 
              and the language exposed through the Document does not support XML Namespaces 
              (such as [HTML 4.01]).


71
72
73
# File 'lib/vcdom/minidom/named_node_map_attr.rb', line 71

def get_named_item_ns( namespace_uri, local_name )
  return @owner_element.get_attribute_node_ns( namespace_uri, local_name )
end

#item(index) ⇒ Object

item

Returns the indexth item in the map. If index is greater than or equal to the number of nodes in this map, this returns null.

Parameters
  index of type unsigned long
    Index into this map.
Return Value
  Node
    The node at the indexth position in the map, or null if that is not a valid index.
No Exceptions


29
30
31
32
33
34
# File 'lib/vcdom/minidom/named_node_map_attr.rb', line 29

def item( index )
  if( index < 0 ) then 
    return nil
  end
  return @nodes[index]
end

#lengthObject

length of type unsigned long, readonly

The number of nodes in this map. 
The range of valid child node indices is 0 to length-1 inclusive.


14
# File 'lib/vcdom/minidom/named_node_map_attr.rb', line 14

def length; return @nodes.size() end

#remove_named_item(name) ⇒ Object

removeNamedItem

Removes a node specified by name. 
When this map contains the attributes attached to an element, if the removed attribute is known to 
have a default value, an attribute immediately appears containing the default value as well as 
the corresponding namespace URI, local name, and prefix when applicable.

Parameters
  name of type DOMString
    The nodeName of the node to remove.
Return Value
  Node
    The node removed from this map if a node with such a name exists.
Exceptions
  DOMException
    NOT_FOUND_ERR: Raised if there is no node named name in this map.
    NO_MODIFICATION_ALLOWED_ERR: Raised if this map is readonly.


195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
# File 'lib/vcdom/minidom/named_node_map_attr.rb', line 195

def remove_named_item( name )
  attr = @owner_element.get_attribute_node( name )
  if ! attr.nil? then
    begin
      return @owner_element.remove_attribute_node( attr )
    rescue DOMException => err
      case err.code
        when DOMException::NO_MODIFICATION_ALLOWED_ERR then
          raise DOMException.new( err.code, 'This map is readonly.' )
        when DOMException::NOT_FOUND_ERR then
          raise DOMException.new( err.code, 'There is no node named name in this map.' )
        else
          raise DOMException.new( err )
      end
    end
  else
    raise DOMException.new( DOMException::NOT_FOUND_ERR, 
            'There is no node named name in this map.' )
  end
end

#remove_named_item_ns(namespace_uri, local_name) ⇒ Object

removeNamedItemNS introduced in DOM Level 2

Removes a node specified by local name and namespace URI. 
A removed attribute may be known to have a default value when this map contains the attributes 
attached to an element, as returned by the attributes attribute of the Node interface.
If so, an attribute immediately appears containing the default value as well as the corresponding 
namespace URI, local name, and prefix when applicable.
Per [XML Namespaces], applications must use the value null as the namespaceURI parameter for methods 
if they wish to have no namespace.

Parameters
  namespaceURI of type DOMString
    The namespace URI of the node to remove.
  localName of type DOMString
    The local name of the node to remove.
Return Value
  Node
    The node removed from this map if a node with such a local name and namespace URI exists.
Exceptions
  DOMException
    NOT_FOUND_ERR: Raised if there is no node with the specified namespaceURI and localName in this map.
    NO_MODIFICATION_ALLOWED_ERR: Raised if this map is readonly.
    NOT_SUPPORTED_ERR: May be raised if the implementation does not support the feature "XML" 
              and the language exposed through the Document does not support XML Namespaces 
              (such as [HTML 4.01]).


241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
# File 'lib/vcdom/minidom/named_node_map_attr.rb', line 241

def remove_named_item_ns( namespace_uri, local_name )
  attr = @owner_element.get_attribute_node_ns( namespace_uri, local_name )
  if ! attr.nil? then
    begin
      return @owner_element.remove_attribute_node( attr )
    rescue DOMException => err
      case err.code
        when DOMException::NO_MODIFICATION_ALLOWED_ERR then
          raise DOMException.new( err.code, 'This map is readonly.' )
        when DOMException::NOT_FOUND_ERR then
          raise DOMException.new( err.code, 'There is no node named name in this map.' )
        else
          raise DOMException.new( err )
      end
    end
  else
    raise DOMException.new( DOMException::NOT_FOUND_ERR, 
            'There is no node named name in this map.' )
  end
end

#set_named_item(arg) ⇒ Object

setNamedItem

Adds a node using its nodeName attribute.
  #=> Node.nodeName を使用するノードを追加します. 
If a node with that name is already present in this map, 
it is replaced by the new one. 
  #=> もし同じ名前 (Node.nodeName) を持つノードが既にこのマップ内にある場合, 新しいものに置き換えられます.
Replacing a node by itself has no effect.
  #=> 自分自身を自分自身で置き換えることは何の効果もありません. 
As the nodeName attribute is used to derive the name which the node must be stored under, 
multiple nodes of certain types (those that have a "special" string value) cannot be stored as 
the names would clash.
  #=> Node.nodeName が, 一意性を保証するために使用される名前を引き出すのに使用されるとき, 名前が衝突してしまうため 
  #=> あるタイプ (「特別な」 文字列値を持っているもの) の複数のノードを保存できません. ...?
This is seen as preferable to allowing nodes to be aliased.
  #=> これはノードが aliased されるのを許容するより望ましいとみなされます.

Parameters
  arg of type Node
    A node to store in this map. 
    The node will later be accessible using the value of its nodeName attribute.
Return Value
  Node
    If the new Node replaces an existing node the replaced Node is returned, otherwise null is returned.
Exceptions
  DOMException
    WRONG_DOCUMENT_ERR: Raised if arg was created from a different document than the one that created 
              this map.
    NO_MODIFICATION_ALLOWED_ERR: Raised if this map is readonly.
    INUSE_ATTRIBUTE_ERR: Raised if arg is an Attr that is already an attribute of another Element object. 
              The DOM user must explicitly clone Attr nodes to re-use them in other elements.
    HIERARCHY_REQUEST_ERR: Raised if an attempt is made to add a node doesn't belong in this NamedNodeMap. 
              Examples would include trying to insert something other than an Attr node 
              into an Element's map of attributes, or a non-Entity node into the DocumentType's map of 
              Entities.


110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/vcdom/minidom/named_node_map_attr.rb', line 110

def set_named_item( arg )
  if arg.node_type != Node::ATTRIBUTE_NODE then
    raise DOMException.new( DOMException::HIERARCHY_REQUEST_ERR, 
            'This map can contain only nodes that are type of Attr.' )
  end
  begin
    replaced_node = @owner_element.set_attribute_node( arg )
  rescue DOMException => err
    case err.code
      when DOMException::WRONG_DOCUMENT_ERR then
        raise DOMException.new( err.code, 'The argument arg was created from a different document than the one that created this map.' )
      when DOMException::NO_MODIFICATION_ALLOWED_ERR then
        raise DOMException.new( err.code, 'This map is readonly.' )
      else
        raise DOMException.new( err )
    end
  end
  return replaced_node
end

#set_named_item_ns(arg) ⇒ Object

setNamedItemNS introduced in DOM Level 2

Adds a node using its namespaceURI and localName. 
If a node with that namespace URI and that local name is already present in this map, 
it is replaced by the new one. Replacing a node by itself has no effect.
Per [XML Namespaces], applications must use the value null as the namespaceURI parameter 
for methods if they wish to have no namespace.

Parameters
  arg of type Node
    A node to store in this map. The node will later be accessible using the value of 
    its namespaceURI and localName attributes.
Return Value
  Node
    If the new Node replaces an existing node the replaced Node is returned, otherwise null is returned.
Exceptions
  DOMException
    WRONG_DOCUMENT_ERR: Raised if arg was created from a different document than the one that created 
              this map.
    NO_MODIFICATION_ALLOWED_ERR: Raised if this map is readonly.
    INUSE_ATTRIBUTE_ERR: Raised if arg is an Attr that is already an attribute of another Element object. 
              The DOM user must explicitly clone Attr nodes to re-use them in other elements.
    HIERARCHY_REQUEST_ERR: Raised if an attempt is made to add a node doesn't belong in this NamedNodeMap. 
              Examples would include trying to insert something other than an Attr node into 
              an Element's map of attributes, or a non-Entity node into the DocumentType's map of Entities.
    NOT_SUPPORTED_ERR: May be raised if the implementation does not support the feature "XML" 
              and the language exposed through the Document does not support XML Namespaces 
              (such as [HTML 4.01]).


158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/vcdom/minidom/named_node_map_attr.rb', line 158

def set_named_item_ns( arg )
  if arg.node_type != Node::ATTRIBUTE_NODE then
    raise DOMException.new( DOMException::HIERARCHY_REQUEST_ERR, 
            'This map can contain only nodes that are type of Attr.' )
  end
  begin
    replaced_node = @owner_element.set_attribute_node_ns( arg )
  rescue DOMException => err
    case err.code
      when DOMException::WRONG_DOCUMENT_ERR then
        raise DOMException.new( err.code, 'The argument arg was created from a different document than the one that created this map.' )
      when DOMException::NO_MODIFICATION_ALLOWED_ERR then
        raise DOMException.new( err.code, 'This map is readonly.' )
      else
        raise DOMException.new( err )
    end
  end
  return replaced_node
end