Hi there,
I’m a bit stuck with roxml (GitHub - Empact/roxml: ROXML is a module for binding Ruby classes to XML. It supports custom mapping and bidirectional marshalling between Ruby and XML using annotation-style class methods, via Nokogiri or LibXML.). I’ve a
webservice which wants me to send a REST-Request with the following body
<ns2:user xmlns:ns2=“http://foo.example.com”>
attr
</ns2:user>
I mastered the REST-part, but found no way to get roxml to write out the
xml-reprensentation the way I need it.
I always get:
ns2:user
attr
</ns2:user>
when translating the object this way
Object.to_xml.to_s
I use the gem of roxml
gem install roxml -v 3.2.1
the following input file
<?xml version="1.0" encoding="UTF-8"?><ns2:user xmlns:ns2=“http://foo.example.com”>
attr
</ns2:user>
and the following script
require ‘roxml’
require ‘pry’
require ‘pp’
class User
include ROXML
#not needed but my real classes look like UserSimple etc.
xml_name 'user'
xml_namespace :ns2
#I also tried it this way
#xml_namespaces :ns2 => 'http://foo.example.com'
xml_accessor :attribute, :namespace => false
end
user = User.from_xml(File.read(File.expand_path(‘example-user.xml’,
File.dirname(FILE))))
pp user.to_xml.to_s
Help would be very welcome, as I’m stuck in the moment and need the
stuff working for my master thesis.
Thanks.
Cheers,
Herbert