我有一个创建的对象模型,xsd.exe
它有这个成员:
XSD:
<xs:element maxOccurs="unbounded" name="Foo">
<xs:complexType>
<xs:attribute name="bar" type="xs:string" />
<xs:anyAttribute />
</xs:complexType>
</xs:element>
生成的 C#(删节)
[XmlAnyAttribute]
public XmlAttribute[] AnyAttr { get... set... }
反序列化很好,当我加载这样的 XML 文件时会填充此属性:
<Foo bar="baz" one="one" two="three" four="ten" />
问题是,我如何序列化?我不能简单地设置fooInstance.AnyAttr = new XmlAttribute[]
然后创建每个XmlAttribute
对象以进入AnyAttr
集合,因为XmlAttribute
构造函数是内部的,只能由XmlDocument.CreateAttribute
. 但是,在当前上下文中,没有XmlDocument
可用的实例。
那么如何创建一个XmlAttribute
适用于 with的实例[XmlAnyAttribute]
呢?