Revision c6c217d4 src/oca/ruby/OpenNebula/XMLUtils.rb

View differences:

src/oca/ruby/OpenNebula/XMLUtils.rb
8 8
        NOKOGIRI=false
9 9
    end
10 10

  
11
    # Require crack library if present, otherwise don't bother
12
    # This is just for OCCI use
13
    begin
14
        require 'crack'
15
    rescue LoadError
16
    end
17 11

  
18 12
    ###########################################################################
19 13
    # The XMLElement class provides an abstraction of the underlying
......
162 156
            str
163 157
        end
164 158

  
165
        def to_hash
166
            if !@hash && @xml
167
                begin
168
                   @hash = Crack::XML.parse(to_xml)
169
                rescue Exception => e
170
                   error = OpenNebula::Error.new(e.message)
171
                   return error
172
                end
173
            end
174
            return @hash
175
        end
176

  
177 159
        def to_xml(pretty=false)
178 160
            if NOKOGIRI
179 161
                @xml.to_xml
......
214 196
                }
215 197
            end
216 198
        end
217

  
218
        def to_hash
219
            if !@hash && @xml
220
                @hash=Crack::XML.parse(to_xml)
221
            end
222
            return @hash
223
        end
224 199
    end
225 200

  
226 201
end

Also available in: Unified diff