Give elements default labels#467
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.
|
👍 |
| } | ||
|
|
||
| trait CanWriteXML[A] { | ||
| def defaultElementLabel: Option[String] = None |
There was a problem hiding this comment.
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.
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.
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.
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.
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
DataRecorddoesn'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
DataRecordis created without a label and yet we still get valid XML.