From: "NAKAMURA, Hiroshi" Date: 2006-11-04T10:51:05+09:00 Subject: Re: adding soap element attributes -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi, Andrew Tongen wrote: > I may consider writing a WSDL for this application, but for now I only > need a subset of fucntionality. The request objects are all pretty > simple, but I am having trouble accessing data from the response > objects. > > After calling: > > get_account = driver.get_account('user@example.com') > > The raw XML response for this command looks something like this: > > > id="770316d9-qwe4-38eu-s84h-2dfe3c6cc874"> > value1 > value2 > value3 > ... > > > > I need to access the key/value pairs in the a attributes, but > get_account.account.a simply returns an array of [value1, value2, > value3, ...] and seems to ignore the attributes. Many response objects > for this app take this form, so it would be nice to be able to create a > hash, or ruby object dynamically based on the key/values. You need to define the service as a document service when you want to handle XML attribute. Try the following. / / / require 'soap/rpc/driver' ns = 'urn:namespace' soapaction = nil driver = SOAP::RPC::Driver.new(nil, ns) driver.add_document_method('get_account', soapaction, XSD::QName.new(ns, 'GetAccountRequest'), XSD::QName.new(ns, 'GetAccountResponse')) driver.test_loopback_response << <<__XML__ value1 value2 value3 __XML__ driver.wiredump_dev = STDOUT ele = SOAP::SOAPString.new('user@example.com') ele.elename = XSD::QName.new(nil, 'account') ele.extraattr[XSD::QName.new(nil, 'by')] = 'name' # !!! a wrapper element is needed for document service. req = SOAP::SOAPElement.new(XSD::QName.new(ns, 'GetAccountRequest')) req.add(ele) get_account = driver.get_account(req) map = {} get_account.account.a.each do |value| map[value.xmlattr_n] = value end p map # => {"key1"=>"value1", "key2"=>"value2", "key3"=>"value3"} # Now you want to write WSDL, don't you? :-) > The app I am using is Zimbra, in case anyone has any experience or > advice for use with Soap4r. Please let me know if you succeeded to use it. Users must be interested in it. Regards, // NaHi -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2.1 (Cygwin) iQEVAwUBRUvx4B9L2jg5EEGlAQLAQAgAp5dEsugVXp1jPPsOJJ10fanLzbK+oFY2 4qQ8tpziNHIIMs5oZVxsv+/hoY+64jrqMoTgmpidZ3Pdo84YS3pwMtSCgda7r9UQ r0sw+JmjUMqfzgdN2tK7A8+nidKGpXYV4PDnWJPfk4iav3Dhk5xtFV8v/oM3WpnQ tqGUV0BcSJ5fmXz+E6rvsG1LPPMQcnGWQI6SSpArYuR0ATdL7ff2HfOBEHAkaqFM 3H401RjnyTrYlHjO+uJUANNgzdVaF/Tl//z0omSSBa3z/uqx5EE6mcmjZSJ0QKTr 6b/xHBeqzpG09XrKgW9VDUjJRkUx9wxewQsrK+6b1RnFU/W0/Owhlg== =SbKf -----END PGP SIGNATURE-----