-
Notifications
You must be signed in to change notification settings - Fork 418
Open
Description
Some XSD have attributes with xsd:dateTime. For instance, http://www.omg.org/spec/ReqIF/20110401/reqif.xsd, used for exchanging requirements between authoring tools, have 24 of them.
<xsd:attribute name="LAST-CHANGE" type="xsd:dateTime" use="required" />At runtime, the marshalling/unmarshalling of an xml will fail
Error parsing XML: cannot unmarshal into soap.XSDDateTime
or
Error parsing XML: cannot marshal into soap.XSDDateTime
To allow for marshalling/unmarshalling, one have to patch the soap package with 2 additional methods.
Below is a non idomatic implementation that works so far
func (xdt XSDDateTime) MarshalXMLAttr(name xml.Name) (xml.Attr, error) {
const myFormat = "2006-01-02T15:04:05.000-07:00"
return xml.Attr{
Name: name,
Value: xdt.ToGoTime().Format(myFormat),
}, nil
}
func (xdt *XSDDateTime) UnmarshalXMLAttr(attr xml.Attr) error {
var err error
const layout = "2006-01-02T15:04:05.000-07:00"
xdt.innerTime, err = time.Parse(layout, attr.Value)
if err != nil {
return fmt.Errorf("could not parse time: %v", err)
}
return nil
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels