Class: Wiris::Xml
- Inherits:
-
Object
- Object
- Wiris::Xml
- Includes:
- Comparable, REXML
- Defined in:
- lib/src-generic/Xml.rb
Constant Summary collapse
- Element =
:element
- PCData =
:text
- CData =
:text
Class Method Summary collapse
Instance Method Summary collapse
- #addChild(x) ⇒ Object
- #attributes ⇒ Object
- #createCData_(text) ⇒ Object
- #createElement_(name) ⇒ Object
- #createPCData_(text) ⇒ Object
- #elements ⇒ Object
- #firstChild ⇒ Object
- #firstElement ⇒ Object
- #get(attributeName) ⇒ Object
- #getNodeValue_ ⇒ Object
-
#initialize(node) ⇒ Xml
constructor
A new instance of Xml.
- #insertChild(x, pos) ⇒ Object
- #iterator ⇒ Object
- #node ⇒ Object
- #node=(node) ⇒ Object
- #nodeName ⇒ Object
- #nodeName=(nodeName) ⇒ Object
- #nodeType ⇒ Object
- #nodeType=(nodeType) ⇒ Object
- #parent_ ⇒ Object
- #remove(attributeName) ⇒ Object
- #removeChild(x) ⇒ Object
- #set(attributeName, attributeValue) ⇒ Object
- #toString ⇒ Object
Constructor Details
#initialize(node) ⇒ Xml
Returns a new instance of Xml.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/src-generic/Xml.rb', line 34 def initialize(node) @node =node @nodeType = node.node_type if node.class == REXML::CData @nodeType = :text end if (@nodeType == :text) @nodeName = :text elsif (@nodeType == :text) @nodeName = :text else @nodeName = node.name end end |
Class Method Details
Instance Method Details
#addChild(x) ⇒ Object
126 127 128 |
# File 'lib/src-generic/Xml.rb', line 126 def addChild(x) @node << x.node end |
#attributes ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/src-generic/Xml.rb', line 74 def attributes() atts = Array.new; if @node.attributes.nil? return Iterator.new end @node.attributes.each_attribute { |attr| atts.push(attr.) } return Iterator.new atts.each end |
#createCData_(text) ⇒ Object
170 171 172 173 |
# File 'lib/src-generic/Xml.rb', line 170 def createCData_(text) elem = REXML::CData.new(text) return Xml.new elem end |
#createElement_(name) ⇒ Object
152 153 154 155 |
# File 'lib/src-generic/Xml.rb', line 152 def createElement_(name) elementNode = REXML::Element.new name return Xml.new elementNode end |
#createPCData_(text) ⇒ Object
157 158 159 160 |
# File 'lib/src-generic/Xml.rb', line 157 def createPCData_(text) textNode = Text.new text return Xml.new textNode end |
#elements ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/src-generic/Xml.rb', line 57 def elements() childElements = Array.new node = nil if (self.firstChild() != nil) node = self.firstChild().node end while (!node.nil?) if (node.node_type == :element) childElements.push(node) end node = node.next_sibling end # return XmlIterator.new(childElements.each) return XmlIterator.new childElements.each end |
#firstChild ⇒ Object
109 110 111 112 113 114 115 |
# File 'lib/src-generic/Xml.rb', line 109 def firstChild() if defined?(@node.each_child).nil? || @node.each_child.count == 0 return nil end return Xml.new @node.each_child.next end |
#firstElement ⇒ Object
117 118 119 120 121 122 123 124 |
# File 'lib/src-generic/Xml.rb', line 117 def firstElement() @node.each_recursive {|e| if e.class == REXML::Element return Xml.new e end } return nil end |
#get(attributeName) ⇒ Object
87 88 89 |
# File 'lib/src-generic/Xml.rb', line 87 def get(attributeName) return @node.attributes[attributeName] end |
#getNodeValue_ ⇒ Object
162 163 164 165 166 167 168 |
# File 'lib/src-generic/Xml.rb', line 162 def getNodeValue_() if (@node.node_type == :text || @node.node_type == :node) return @node.value else return @node.text end end |
#insertChild(x, pos) ⇒ Object
130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/src-generic/Xml.rb', line 130 def insertChild(x, pos) if pos < 0 end # On ruby first index starts at 1. # Check if node has childs, if not insert node directly. if @node.elements[1].nil? xmlparsed.firstChild.addChild(x) else @node.insert_before(@node.elements[1], x.node) end end |
#iterator ⇒ Object
53 54 55 |
# File 'lib/src-generic/Xml.rb', line 53 def iterator() return XmlIterator.new(@node.each) end |
#node ⇒ Object
16 17 18 |
# File 'lib/src-generic/Xml.rb', line 16 def node @node end |
#node=(node) ⇒ Object
13 14 15 |
# File 'lib/src-generic/Xml.rb', line 13 def node=(node) @node=node end |
#nodeName ⇒ Object
23 24 25 |
# File 'lib/src-generic/Xml.rb', line 23 def nodeName @nodeName end |
#nodeName=(nodeName) ⇒ Object
20 21 22 |
# File 'lib/src-generic/Xml.rb', line 20 def nodeName=(nodeName) @nodeName=nodeName end |
#nodeType ⇒ Object
30 31 32 |
# File 'lib/src-generic/Xml.rb', line 30 def nodeType @nodeType end |
#nodeType=(nodeType) ⇒ Object
27 28 29 |
# File 'lib/src-generic/Xml.rb', line 27 def nodeType=(nodeType) @nodeType=nodeType end |
#parent_ ⇒ Object
102 103 104 105 106 107 |
# File 'lib/src-generic/Xml.rb', line 102 def parent_() if @node.parent.nil? return nil end return Xml.new @node.parent end |
#remove(attributeName) ⇒ Object
91 92 93 94 95 |
# File 'lib/src-generic/Xml.rb', line 91 def remove(attributeName) if !@node.attributes[attributeName].nil? @node.attributes.delete attributeName end end |
#removeChild(x) ⇒ Object
141 142 143 144 145 146 |
# File 'lib/src-generic/Xml.rb', line 141 def removeChild(x) remove = @node == x.node.parent if remove x.node.remove end end |
#set(attributeName, attributeValue) ⇒ Object
97 98 99 100 |
# File 'lib/src-generic/Xml.rb', line 97 def set(attributeName, attributeValue) newAtrribute = REXML::Attribute.new(attributeName, attributeValue); @node.attributes.add(newAtrribute) end |
#toString ⇒ Object
175 176 177 |
# File 'lib/src-generic/Xml.rb', line 175 def toString() return @node.to_s end |