.net 使用F更改XML序列化中的标记名#
这就是我得到的:.net 使用F更改XML序列化中的标记名#,.net,f#,xml-serialization,.net,F#,Xml Serialization,这就是我得到的: <Recipients> <recipients> <mid_name /> <last_name>Community</last_name> <company>co, inc.</company> <user_id>871</user_id>
<Recipients>
<recipients>
<mid_name />
<last_name>Community</last_name>
<company>co, inc.</company>
<user_id>871</user_id>
<email>community@co.com</email>
</recipients>
</Recipients>
社区
公司。
871
community@co.com
应该是这样的
<recipients>
<recipient>
<mid_name />
<last_name>Community</last_name>
<company>co, inc.</company>
<user_id>871</user_id>
<email>community@co.com</email>
</recipient>
</recipients>
社区
公司。
871
community@co.com
这就是我的数据模型的样子:
type recipient(userId:int, first:string, last:string, email: string, company: string) =
let mutable first = first
let mutable mid = "" ;
let mutable last = last
let mutable company = company
let mutable userId = userId
let mutable email = email
public new() =
new recipient(12180,"Joe","Plumber","Joe@plumber.com","tubes tied, inc")
[<XmlElement("first_name")>]
member this.First with get() = first and set v = first <- v
[<XmlElement("mid_name")>]
member this.Mid with get() = mid and set v = mid <- v
[<XmlElement("last_name")>]
member this.Last with get() = last and set v = last <- v
[<XmlElement("company")>]
member this.Company with get() = company and set v = company <- v
[<XmlElement("user_id")>]
member this.UserId with get() = userId and set v = userId <- v
[<XmlElement("email")>]
member this.Email with get() = email and set v = email <- v
键入收件人(userId:int,first:string,last:string,email:string,company:string)=
设mutable first=first
让可变中间=”;
让可变的last=last
让可变公司=公司
让可变userId=userId
让可变电子邮件=电子邮件
公共新=
新接受者(12180,“乔”,“管道工”Joe@plumber.com“,“管系公司”)
[]
使用get()=First和set v=First来成员this.First我认为应该使用
[<XmlElement "recipients">]
[]
现在看起来您正在用数组属性装饰数组
此外,您可以将ElementName=“recipients”设置为“recipient”
这是一个更完整的示例,我考虑了其他属性:
type recipient (f:string) =
let mutable first = f
public new () = recipient ("")
[<System.Xml.Serialization.XmlElement("first_name")>]
member this.First with get() = first and set v = first <- v
[<System.Xml.Serialization.XmlRoot("recipients")>]
type Record (recepts: recipient array) =
let mutable recipients = recepts
public new () = Record(Array.empty)
[<System.Xml.Serialization.XmlElement("recipient")>]
member this.Recipients with get() = recipients and set v = recipients <- v
类型收件人(f:string)=
设可变优先=f
public new()=收件人(“”)
[]
使用get()=First和set v=First来成员this.First我认为应该使用
[<XmlElement "recipients">]
[]
现在看起来您正在用数组属性装饰数组
此外,您可以将ElementName=“recipients”设置为“recipient”
这是一个更完整的示例,我考虑了其他属性:
type recipient (f:string) =
let mutable first = f
public new () = recipient ("")
[<System.Xml.Serialization.XmlElement("first_name")>]
member this.First with get() = first and set v = first <- v
[<System.Xml.Serialization.XmlRoot("recipients")>]
type Record (recepts: recipient array) =
let mutable recipients = recepts
public new () = Record(Array.empty)
[<System.Xml.Serialization.XmlElement("recipient")>]
member this.Recipients with get() = recipients and set v = recipients <- v
类型收件人(f:string)=
设可变优先=f
public new()=收件人(“”)
[]
请记住这一点。首先,使用get()=First和set v=FirstAlex非常接近,您需要的魔法juju是将[]
放在非常接近的位置,您需要的魔法jujuju是将[]放在非常接近的位置。在记录类型中,存在类型为recipient.yes的收件人数组。在记录类型中,存在类型为recipient的收件人数组。
<recipients xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<recipient>
<first_name>a</first_name>
</recipient>
<recipient>
<first_name>b</first_name>
</recipient>
<recipient>
<first_name>c</first_name>
</recipient>