Skip to content
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

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open

Conversation

hosamaly
Copy link
Contributor

@hosamaly hosamaly commented Mar 13, 2018

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.

The test at the end demonstrates the usage, where a DataRecord is created without a label and yet we still get valid XML.

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.
hosamaly added a commit to guardian/nitf-scala that referenced this pull request Mar 13, 2018
hosamaly added a commit to guardian/nitf-scala that referenced this pull request Mar 13, 2018
@LATaylor-guardian
Copy link

👍

hosamaly added a commit to guardian/nitf-scala that referenced this pull request Mar 14, 2018
@@ -62,6 +62,7 @@ trait CanReadXML[A] {
}

trait CanWriteXML[A] {
def defaultElementLabel: Option[String] = None
Copy link
Owner

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.

Copy link
Owner

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.

Copy link
Contributor Author

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?

Copy link

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.

Copy link

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

@hamnis
Copy link

hamnis commented Oct 14, 2021

Something like this would be very useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants