Class: DBus::IntrospectXMLParser
- Inherits:
-
Object
- Object
- DBus::IntrospectXMLParser
- Defined in:
- lib/dbus/introspect.rb
Overview
D-Bus introspect XML parser class
This class parses introspection XML of an object and constructs a tree of Node, Interface, Method, Signal instances.
Instance Method Summary collapse
-
#initialize(xml) ⇒ IntrospectXMLParser
constructor
Creates a new parser for XML data in string xml.
-
#parse ⇒ Object
Parses the XML, constructing the tree.
-
#parse_subnodes ⇒ Object
Recursively parses the subnodes, constructing the tree.
Constructor Details
#initialize(xml) ⇒ IntrospectXMLParser
Creates a new parser for XML data in string xml.
200 201 202 |
# File 'lib/dbus/introspect.rb', line 200 def initialize(xml) @xml = xml end |
Instance Method Details
#parse ⇒ Object
Parses the XML, constructing the tree.
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 |
# File 'lib/dbus/introspect.rb', line 216 def parse ret = Array.new subnodes = Array.new t = Time.now d = REXML::Document.new(@xml) d.elements.each("node/node") do |e| subnodes << e.attributes["name"] end d.elements.each("node/interface") do |e| i = Interface.new(e.attributes["name"]) e.elements.each("method") do |me| m = Method.new(me.attributes["name"]) parse_methsig(me, m) i << m end e.elements.each("signal") do |se| s = Signal.new(se.attributes["name"]) parse_methsig(se, s) i << s end ret << i end d = Time.now - t if d > 2 puts "Some XML took more that two secs to parse. Optimize me!" if $DEBUG end [ret, subnodes] end |
#parse_subnodes ⇒ Object
Recursively parses the subnodes, constructing the tree.
205 206 207 208 209 210 211 212 213 |
# File 'lib/dbus/introspect.rb', line 205 def parse_subnodes subnodes = Array.new t = Time.now d = REXML::Document.new(@xml) d.elements.each("node/node") do |e| subnodes << e.attributes["name"] end subnodes end |