-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add schemaLocation if present #68
Conversation
e09547b
to
e4d2b50
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@HassanAkbar I've added a README and some specs to test for multiple schemaLocations. As you can see here, there could be multiple schemaLocations, and we need to support that. Can you help revise and update the feature/specs?
@ronaldtse I've updated the code according to the specs you added, I just changed how the |
Somehow this is failing... class Ceramic < Lutaml::Model::Serializable
attribute :type, :string
attribute :glaze, :string
attribute :color, :string
xml do
root 'Ceramic'
namespace 'http://example.com/ceramic', 'cera'
map_element 'Type', to: :type, namespace: :inherit
map_element 'Glaze', to: :glaze
map_attribute 'color', to: :color, namespace: 'http://example.com/color', prefix: 'clr'
end
end
xml = <<~HERE
<cera:Ceramic
xmlns:cera="http://example.com/ceramic"
xmlns:clr="http://example.com/color"
xsi:schemaLocation=
"http://example.com/ceramic http://example.com/ceramic.xsd
http://example.com/color http://example.com/color.xsd"
clr:color="navy-blue">
<cera:Type>Porcelain</cera:Type>
<Glaze>Clear</Glaze>
</cera:Ceramic>
HERE
Ceramic.from_xml(xml) @HassanAkbar any idea? |
Actually it works! Sorry!! |
No actually it doesn't? $ bundle console
# ...
require_relative "../lib/lutaml/model/xml_adapter/nokogiri_adapter"
Lutaml::Model::Config.configure do |config|
config.xml_adapter_type = :nokogiri
end
class Ceramic < Lutaml::Model::Serializable
attribute :type, :string
attribute :glaze, :string
attribute :color, :string
xml do
root 'Ceramic'
namespace 'http://example.com/ceramic', 'cera'
map_element 'Type', to: :type, namespace: :inherit
map_element 'Glaze', to: :glaze
map_attribute 'color', to: :color, namespace: 'http://example.com/color', prefix: 'clr'
end
end
xml_content = <<~HERE
<cera:Ceramic
xmlns:cera="http://example.com/ceramic"
xmlns:clr="http://example.com/color"
xsi:schemaLocation=
"http://example.com/ceramic http://example.com/ceramic.xsd
http://example.com/color http://example.com/color.xsd"
clr:color="navy-blue">
<cera:Type>Porcelain</cera:Type>
<Glaze>Clear</Glaze>
</cera:Ceramic>
HERE
a = Ceramic.from_xml(xml_content)
a.schema_location
# => nil |
The tests are just illustrative but the way it works seems fine to me. |
@ronaldtse This is happening because the I'll update the code to handle this scenario. |
Ahh @HassanAkbar yes you are right. We need to define the namespace xsi first. My example XML was mistaken. It’s fine then. |
@ronaldtse Then I think this is done. Is there something else left to be done in this PR? |
This is all good, I've tested it with the (updated) sample in the README. Merging once tests pass. |
Automatically support
xsi:schemaLocation
for all XML elements if present in XMLcloses #64