-
Notifications
You must be signed in to change notification settings - Fork 156
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
Give elements default labels #467
base: develop
Are you sure you want to change the base?
Conversation
These default labels are to be used when a DataRecord doesn't have a label. This helps with generating XML from a memory model without having to know about the XML tags.
👍 |
@@ -62,6 +62,7 @@ trait CanReadXML[A] { | |||
} | |||
|
|||
trait CanWriteXML[A] { | |||
def defaultElementLabel: Option[String] = None |
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.
I am not sure if doing is this in CanWriteXML[A]
makes sense. A
represents the inside of the <x>1</x>
element, not x
. Whereas DataRecord[A]
represents both.
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.
There are situations where the element name is obvious, but in those cases maybe we need typeclass instance for DataRecord[A]
, or maybe a new typclass that extends CanWriteXML
.
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.
Thanks for your feedback, Eugene. I'm not sure how to implement these suggestions without making significant changes to the code base. Can you think of a (relatively easy) way to do this?
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.
My impression was that A
has a 1-1 correspondence with the schema from which it was generated. I figure scalaxb should know about that top-level element name for that type, because it was in that schema. I'd like to be able to retrieve that without parsing the xsd myself - which kind of defeats some of the point of scalaxb for me.
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.
The use case is that there be some kind of "ToXML" typeclass that includes enough information to render an instance of that type as an XML document, e.g. for an HTTP response (where the user can choose to have the instance rendered as JSON or XML). Such as is done for http://hackage.haskell.org/package/servant-xml-1.0.1.2/docs/Servant-XML.html
Something like this would be very useful. |
These default labels are to be used when a
DataRecord
doesn't have alabel. This helps with generating XML from a memory model without having
to know about the XML tags.
The test at the end demonstrates the usage, where a
DataRecord
is created without a label and yet we still get valid XML.