I have a requirement to create XML that looks like this:
<record id="100000000000000000" type="Message">
...a bunch of xml ...
</record>
instead, with the FSsharp code I'm using, i'm getting this:
<record>
<type>Message</type>
<id>118448</id>
...a bunch of xml....
</record>
here's what I'm currently doing:
type record( id:int, sr:sender, recipients: recipient array, atts : attachment array, con : conversation, madeDate : creation) =
let mutable id: int = id
let mutable typ = "Message"
let mutable creation = madeDate
let mutable sender = sr
let mutable recipients = recipients
let mutable conversation = con
let mutable attachments = atts
public new() =
record( -1, sender(-1,"Joe","Plumber","[email protected]"), Array.empty, Array.empty, conversation(), creation())
[<XmlElement("type")>]
member this.Type with get() = typ and set v = typ <- v
[<XmlElementAttribute("id")>]
member this.Id with get() = id and set v = id <- v
[<XmlElement("creation")>]
member this.Creation with get() = creation and set v = creation <- v
[<XmlElement("sender")>]
member this.Sender with get() = sender and set v = sender <- v
[<XmlArrayAttribute("recipients")>]
[<XmlArrayItem(typeof<recipient>, ElementName = "recipient")>]
member this.Recipients with get() = recipients and set v = recipients <- v
[<XmlElement("conversation_info")>]
member this.Conversation with get() = conversation and set v = conversation <- v
[<XmlArrayAttribute("attachments")>]
[<XmlArrayItem(typeof<attachment>, ElementName = "attachment")>]
member this.Attachments with get() = attachments and set v = attachments <- v
I think you want XmlAttributeAttribute
instead of XmlElementAttribute
.
Note that
[<XmlElement>]
and
[<XmlElementAttribute>]
are the same thing (just like C#).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With