-
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
Open
hosamaly
wants to merge
1
commit into
eed3si9n:develop
Choose a base branch
from
hosamaly:master
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
integration/src/test/resources/can_write_default_label.xsd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<schema xmlns="http://www.w3.org/2001/XMLSchema" | ||
xmlns:defaultLabels="http://www.example.com/default-labels" | ||
targetNamespace="http://www.example.com/default-labels"> | ||
|
||
<element name="docdata"> | ||
<complexType> | ||
<choice minOccurs="0" maxOccurs="unbounded"> | ||
<element ref="defaultLabels:docid"/> | ||
<element ref="defaultLabels:urgency"/> | ||
</choice> | ||
</complexType> | ||
</element> | ||
|
||
<element name="urgency"> | ||
<complexType> | ||
<attribute name="urg" type="NMTOKEN"/> | ||
</complexType> | ||
</element> | ||
<element name="docid"> | ||
<complexType> | ||
<attribute name="idstring" type="string"/> | ||
</complexType> | ||
</element> | ||
</schema> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import scalaxb.compiler.Config | ||
import scalaxb.compiler.ConfigEntry._ | ||
|
||
object CanWriteDefaultLabelTest extends TestBase { | ||
private val schemaFile = resource("can_write_default_label.xsd") | ||
|
||
private def generate() = { | ||
val config = Config.default.update(Outdir(tmp)).update(PackageNames(Map(None -> Some("defaultLabels")))) | ||
module.process(schemaFile, config) | ||
} | ||
|
||
"XML generation falls back to default labels if none are specified" >> { | ||
repl(generate())( | ||
s""" | ||
import defaultLabels._ | ||
import scalaxb.DataRecord | ||
|
||
val urgency = Urgency() | ||
val docId = Docid() | ||
val options = Seq(DataRecord(urgency), DataRecord(None, Some("customDocIdTag"), docId)) | ||
scalaxb.toXML(Docdata(options), "docdata", scala.xml.TopScope).toString | ||
""", expectedResult = scala.xml.Utility.trim( | ||
<docdata> | ||
<urgency /> | ||
<customDocIdTag /> | ||
</docdata>).toString) | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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, notx
. WhereasDataRecord[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 extendsCanWriteXML
.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