Hi,

> From: why the lucky stiff
> Sent: Wednesday, March 19, 2003 11:57 PM

> > In most of my use cases, yes.  If I want typing info, it's
> > easy enough to add when and where I want it.  I prefer it
> > to be an option, not a requirement.

> Typing is an option.  Think of typing information as metadata 
> provided to the 
> loader, indicating how a node should be loaded.  As YAML 
> loaders improve and 
> move forward, you'll see the ability to change typing on 
> nodes based on YPath 
> expressions and schemas.  Typing "when and where" you want it.

Sorry for bothering with XML staff, here is WSDL + WSDL4R
example.


###
## WSDL; interface definition.
#
$ cat person.wsdl
<?xml version="1.0"?>
<definitions name="Person"
    targetNamespace="http://www.ruby-lang.org/xmlns/ruby/type/custom"
    xmlns:tns="http://www.ruby-lang.org/xmlns/ruby/type/custom"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns="http://schemas.xmlsoap.org/wsdl/">
  <types>
    <xsd:schema xmlns="http://www.w3.org/2001/XMLSchema"
        targetNamespace="http://www.ruby-lang.org/xmlns/ruby/type/custom">
      <complexType name="Person">
        <all>
          <element name="familyname" type="xsd:string"/>
          <element name="givenname" type="xsd:string"/>
          <element name="var1" type="xsd:int"/>
          <element name="var2" type="xsd:double"/>
          <element name="var3" type="xsd:string"/>
        </all>
      </complexType>
    </xsd:schema>
  </types>
</definitions>

###
## Generate Ruby's class definition from the WSDL file.
#
$ wsdl2ruby.rb --wsdl person.wsdl --classDef --force
I, [2003-03-20T09:36:22.387171 #2416]  INFO -- app: Start of app.
I, [2003-03-20T09:36:22.416171 #2416]  INFO -- app: Creating class definition.
I, [2003-03-20T09:36:22.419171 #2416]  INFO -- app: Creates file 'Person.rb'.
I, [2003-03-20T09:36:22.433171 #2416]  INFO -- app: End of app. (status: 0)

###
## WSDL based marshalling example.
#
$ cat wsdlmarshaller.rb
require 'wsdl/parser'
require 'soap/marshal'

class WSDLMarshaller
  include SOAP

  def initialize(wsdlFile)
    wsdl = WSDL::WSDLParser.createParser.parse(
      File.open(wsdlFile).read)
    @opt = {
      :decodeComplexTypes => wsdl.collectComplexTypes,
      :generateEncodeType => false
    }
  end

  def dump(obj, io = nil)
    ele =  Mapping.obj2soap(obj)
    # WSDL4R does not support element name based complexType for now
    # (type based complexType only.)
    ele.elementName = ele.type
    Processor.marshal(nil, SOAPBody.new(ele), @opt, io)
  end

  def load(io)
    header, body = Processor.unmarshal(io, @opt)
    Mapping.soap2obj(body.rootNode)
  end
end

marshaller = WSDLMarshaller.new('Person.wsdl')

require 'Person'
obj = Person.new("NAKAMURA", "Hiroshi", 1, 1.0,  "1")
str = marshaller.dump(obj)
puts str
puts
require 'pp'
pp marshaller.load(str)

###
## run
#
$ ruby wsdlmarshaller.rb
<?xml version="1.0" encoding="utf-8" ?>
<env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:env="http://sch
emas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-ins
tance">
<env:Body>
<n2:Person xmlns:n1="http://schemas.xmlsoap.org/soap/encoding/" xmlns:n2="http:/
/www.ruby-lang.org/xmlns/ruby/type/custom" env:encodingStyle="http://schemas.xml
soap.org/soap/encoding/">
<familyname>NAKAMURA</familyname>
<givenname>Hiroshi</givenname>
<var1>1</var1>
<var2>1</var2>
<var3>1</var3>
</n2:Person>
</env:Body>
</env:Envelope>

#<Person:0xa243d88
 @familyname="NAKAMURA",
 @givenname="Hiroshi",
 @var1=1,
 @var2=1.0,
 @var3="1">

$


The XML instance above; (reindented by hand)

<n2:Person
    xmlns:n1="http://schemas.xmlsoap.org/soap/encoding/"
    xmlns:n2="http://www.ruby-lang.org/xmlns/ruby/type/custom"
    env:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
  <familyname>NAKAMURA</familyname>
  <givenname>Hiroshi</givenname>
  <var1>1</var1>
  <var2>1</var2>
  <var3>1</var3>
</n2:Person>

may be enough readable for some purpose (but I agree that
it's still hard to edit as a configuration file.  At least
I don't adopt it for my product.  Go YAML!)

# Hmm.  In the above example, I found "xmlns:n1=..." and
# "env:encodingStyle=..." could be removed.  It should be
# more simple XML instance.

Regards,
// NaHi