-
Notifications
You must be signed in to change notification settings - Fork 0
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
Add raw option for attributes #94
Conversation
@ronaldtse by looking at this comment it seems like a case for class RichText < Lutaml::Model::Serializable
attribute :raw_string, :string
xml do
root 'RichText', raw: true
map_content to: :raw_string
end
end
class Docid < Lutaml::Model::Serializable
attribute :raw_string, RichText
xml do
root 'docid'
map_content to: :raw_string
end
end |
@HassanAkbar I think there are two reasons why @opoudjis and @andrew2net want an enhancement here:
|
child.children.map do |c| | ||
next c.text if c.text? | ||
|
||
self.class.new(c).to_xml |
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 let's merge this first, but is it possible to obtain the full raw string instead of serializing it again? I just don't want to modify something that is meant to be "raw".
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.
@ronaldtse the conversion in lutaml-model
has 2 steps
- Data is parsed using the adapter and saved in the adapter document class (at this point we have no idea which classes have which mappings defined)
- Mappings are used to convert that data to ruby object
The problem is that when we are parsing the data we do not have access to the mappings so we have no idea which content to read as raw string and which to parse. So that is why we are converting the parsed data back to XML string when applying mappings.
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.
Can’t the parser return us the raw XML string at a certain node?
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.
@ronaldtse It will require some changes in the adapters but I think it will work something like
value = if child.text?
child.text
elsif attr&.raw?
child.to_xml
else
parse_element(child, attr&.type || klass, format)
end
I'll open a separate PR for this.
@HassanAkbar can we rebase and merge this? Thanks! |
9195d0c
to
66f649e
Compare
Add
raw
tag for attributes to keep the raw xml as value of that attribute.fixes #90