Skip to content

Instantly share code, notes, and snippets.

@sshaw
Last active August 29, 2015 14:03
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save sshaw/df0b8cda2b9b31875b74 to your computer and use it in GitHub Desktop.
Nokorigi HappyMapper Qualified/Unqualified Namespace Parsing
#
# Auto-generated by jaxb2ruby v0.0.1 on 2014-07-05 13:57:07 -0400
# https://github.com/sshaw/jaxb2ruby
#
require "happymapper"
module Com module Example module Person
class Person
include HappyMapper
register_namespace "ns2", "http://example.com/person"
tag "Person"
element :name, String, :tag => "name", :namespace => "ns2"
end
end end end
module Com module Example module Company
class Company
include HappyMapper
register_namespace "ns1", "http://example.com/company"
namespace "ns1"
tag "Company"
element :name, String, :tag => "name", :namespace => "ns1"
end
end end end
module Com module Example module Person
class Info
include HappyMapper
register_namespace "ns2", "http://example.com/person"
register_namespace "ns1", "http://example.com/company"
namespace "ns2"
tag "Info"
has_one :person, Com::Example::Person::Person, :tag => "person", :namespace => "ns2"
has_one :company, Com::Example::Company::Company, :tag => "Company", :namespace => "ns1"
end
end end end
puts Com::Example::Person::Info.parse(File.read("qualified.xml")).to_xml
<?xml version="1.0" encoding="UTF-8"?>
<q:Info xmlns:q="http://example.com/person" xmlns:c="http://example.com/company">
<q:person>
<q:name>sshaw</q:name>
</q:person>
<c:Company>
<c:name>Crap LLC</c:name>
</c:Company>
</q:Info>
#
# Auto-generated by jaxb2ruby v0.0.1 on 2014-07-05 13:29:10 -0400
# https://github.com/sshaw/jaxb2ruby
#
require "happymapper"
module Com module Example module Person
class Person
include HappyMapper
register_namespace "ns2", "http://example.com/person"
tag "Person"
element :name, String, :tag => "name", :namespace => nil
end
end end end
module Com module Example module Company
class Company
include HappyMapper
register_namespace "ns1", "http://example.com/company"
namespace "ns1"
tag "Company"
element :name, String, :tag => "name", :namespace => nil
end
end end end
module Com module Example module Person
class Info
include HappyMapper
register_namespace "ns2", "http://example.com/person"
register_namespace "ns1", "http://example.com/company"
namespace "ns2"
tag "Info"
has_one :person, Com::Example::Person::Person, :tag => "person", :namespace => nil
has_one :company, Com::Example::Company::Company, :tag => "Company", :namespace => "ns1"
end
end end end
puts Com::Example::Person::Info.parse(File.read("unqualified.xml")).to_xml
<?xml version="1.0" encoding="UTF-8"?>
<q:Info xmlns:q="http://example.com/person" xmlns:c="http://example.com/company">
<person>
<name>sshaw</name>
</person>
<c:Company>
<name>Crap LLC</name>
</c:Company>
</q:Info>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment