altinn-studio
altinn-studio copied to clipboard
The original targetNamespace from an XSD must be included in the resulting C# class
Description
The target namespace as defined by an XSD needs to be included when a model is serialized to XML. The generated C# classes must include a namespace assignment in the XmlRoot attribute that's decorating the class.
<xsd:schema
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified"
attributeFormDefault="unqualified"
targetNamespace="urn:no:altinn:message">
<xsd:element name="Message" type="Message" />
<xsd:complexType name="Message">
<xsd:sequence>
<xsd:element name="Title" nillable="true" type="xsd:string" />
<xsd:element name="Body" nillable="true" type="xsd:string" />
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
namespace Altinn.App.Models
{
[XmlRoot(ElementName="Message", Namespace="urn:no:altinn:message")]
public class Message
{
[XmlElement("Title")]
[JsonProperty("Title")]
[JsonPropertyName("Title")]
public string Title { get; set; }
[XmlElement("Body")]
[JsonProperty("Body")]
[JsonPropertyName("Body")]
public string Body { get; set; }
}
}
Considerations
Are there other ways to define a namespace? Most seres schemas do not have a target namespace.
Acceptance criteria
Describe criteria here (i.e. What is allowed/not allowed (negative tesing), validations, error messages and warnings etc.)
Specification tasks
- [ ] Development tasks are defined
Development tasks
Add tasks here
Test
Add test cases here as checkboxes that are being tested as part of the changes.
Definition of done
Verify that this issue meets DoD (Only for project members) before closing.
- [ ] Documentation is updated (if relevant)
- [ ] Technical documentation (docs.altinn.studio)
- [ ] User documentation (altinn.github.io/docs)
- [ ] QA
- [ ] Manual test is complete (if relevant)
- [ ] Automated test is implemented (if relevant)
- [ ] All tasks in this userstory are closed (i.e. remaining tasks are moved to other user stories or marked obsolete)