# Setting the namespace of an object

**URL:** <https://www.ruby-forum.com/t/setting-the-namespace-of-an-object/54880>\
**Category:** Ruby\
**Created:** [March 14, 2006, 11:36pm UTC](https://www.ruby-forum.com/t/setting-the-namespace-of-an-object/54880 "2006-03-14T23:36:14Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![dbf](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/7feea3/32.png) [@dbf](https://www.ruby-forum.com/u/dbf)\
**Post date:** [March 14, 2006, 11:36pm UTC](https://www.ruby-forum.com/t/setting-the-namespace-of-an-object/54880/1 "2006-03-14T23:36:14Z")

</div>

I posted this to the soap mailing list but have not received any input.  
Hopefully someone here knows the answer.

I am wondering how to change the namespace (xmlns) on the SetResponse  
element from “[http://www.ruby-lang.org/xmlns/ruby/type/custom](http://www.ruby-lang.org/xmlns/ruby/type/custom)” to a  
different namespace using soap4r.

The following code produces the soap message below.

require ‘soap/mapping’  
require ‘soap/processor’

class SetResult  
attr\_accessor :timestamp  
attr\_accessor :errorCode  
attr\_accessor :message  
attr\_accessor :id  
attr\_accessor :version  
end

class SetResponse  
attr\_accessor :SetResult  
end

response\_object = SetResponse.new  
result = SetResult.new  
result.id = 1  
result.version = 2  
result.errorCode = 0  
result.message = ‘Update Successful’  
result.timestamp = Time.new.strftime(‘%Y-%m-%dT%H:%M:%S’)  
response\_object.SetResult = result

soap\_header = SOAP::SOAPHeader.new  
elename = SOAP::Mapping.name2elename(‘SetResponse’)  
mapping\_registry = SOAP::Mapping::Registry.new(:allow\_original\_mapping  
=\> false)  
soap\_obj = SOAP::Mapping.obj2soap(response\_object, mapping\_registry)  
body = SOAP::SOAPBody.new  
body.add(elename, soap\_obj)  
soap = SOAP::SOAPEnvelope.new(soap\_header, body)  
puts SOAP::Processor.marshal(soap, {}, nil)

Returns:

\<?xml version="1.0" encoding="us-ascii" ?\>

\<env:Envelope xmlns:xsd=“[XML Schema](http://www.w3.org/2001/XMLSchema)”  
xmlns:env=“[http://schemas.xmlsoap.org/soap/envelope/](http://schemas.xmlsoap.org/soap/envelope/)”  
xmlns:xsi=“[http://www.w3.org/2001/XMLSchema-instance](http://www.w3.org/2001/XMLSchema-instance)”\>  
env:Body  
  
  
2006-03-09T02:25:56  
1  
2  
Update Successful  
0  
  
  
\</env:Body\>  
\</env:Envelope\>

I need to change:

\<SetResponse  
xmlns:n1=“[http://www.ruby-lang.org/xmlns/ruby/type/custom](http://www.ruby-lang.org/xmlns/ruby/type/custom)” …

to for example:

\<SetResponse xmlns=“[http://example.com/company](http://example.com/company)” …

I also do not need the xsi:type in the soap message either. How do you  
hide those attributes?

Thanks,

Dan
