| Class | REXML::Light::Node |
| In: |
|
| Parent: | Object |
Constants
| NAMESPLIT | = | /^(?:(#{XMLTokens::NCNAME_STR}):)?(#{XMLTokens::NCNAME_STR})/u |
| PARENTS | = | [ :element, :document, :doctype ] |
Public Class methods
Create a new element.
21: def initialize node=nil 22: @node = node 23: if node.kind_of? String 24: node = [ :text, node ] 25: elsif node.nil? 26: node = [ :document, nil, nil ] 27: elsif node[0] == :start_element 28: node[0] = :element 29: elsif node[0] == :start_doctype 30: node[0] = :doctype 31: elsif node[0] == :start_document 32: node[0] = :document 33: end 34: end
Public Instance methods
Append a child to this element, optionally under a provided namespace. The namespace argument is ignored if the element argument is an Element object. Otherwise, the element argument is a string, the namespace (if provided) is the namespace the element is created in.
122: def << element 123: if node_type() == :text 124: at(-1) << element 125: else 126: newnode = Node.new( element ) 127: newnode.parent = self 128: self.push( newnode ) 129: end 130: at(-1) 131: end
86: def []( reference, ns=nil ) 87: if reference.kind_of? String 88: pfx = '' 89: pfx = "#{prefix(ns)}:" if ns 90: at(3)["#{pfx}#{reference}"] 91: elsif reference.kind_of? Range 92: _old_get( Range.new(4+reference.begin, reference.end, reference.exclude_end?) ) 93: else 94: _old_get( 4+reference ) 95: end 96: end
Doesn‘t handle namespaces yet
103: def []=( reference, ns, value=nil ) 104: if reference.kind_of? String 105: value = ns unless value 106: at( 3 )[reference] = value 107: elsif reference.kind_of? Range 108: _old_put( Range.new(3+reference.begin, reference.end, reference.exclude_end?), ns ) 109: else 110: if value 111: _old_put( 4+reference, ns, value ) 112: else 113: _old_put( 4+reference, ns ) 114: end 115: end 116: end
52: def name=( name_str, ns=nil ) 53: pfx = '' 54: pfx = "#{prefix(ns)}:" if ns 55: _old_put(2, "#{pfx}#{name_str}") 56: end
79: def namespace=( namespace ) 80: @prefix = prefix( namespace ) 81: pfx = '' 82: pfx = "#@prefix:" if @prefix.size > 0 83: _old_put(1, "#{pfx}#@name") 84: end