1

我使用 xsd.exe /classes cwmp-1-1.xsd 来生成 c# 代码。

以下代码由该工具生成。

public partial class Array 
{
    [System.Xml.Serialization.XmlAnyElementAttribute()]
    public System.Xml.XmlElement[] Any;
    [System.Xml.Serialization.XmlAttributeAttribute(Form = System.Xml.Schema.XmlSchemaForm.Qualified)]
    public string arrayType;
    [System.Xml.Serialization.XmlAttributeAttribute(Form = System.Xml.Schema.XmlSchemaForm.Qualified)]
    public string offset;
    [System.Xml.Serialization.XmlIgnoreAttribute()]
    public bool offsetSpecified;
    [System.Xml.Serialization.XmlAttributeAttribute(DataType = "ID")]
    public string id;
    [System.Xml.Serialization.XmlAttributeAttribute(DataType = "anyURI")]
    public string href;
    [System.Xml.Serialization.XmlAnyAttributeAttribute()]
    public System.Xml.XmlAttribute[] AnyAttr;
}

public partial class EventList : Array
{
}

public partial class EventStruct
{
    [System.Xml.Serialization.XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
    public string EventCode;
    [System.Xml.Serialization.XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
    public string CommandKey;
}

public partial class Inform
{
    [System.Xml.Serialization.XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
    public DeviceIdStruct DeviceId;
    [System.Xml.Serialization.XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
    public EventList Event;
    [System.Xml.Serialization.XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
    public uint MaxEnvelopes;
    [System.Xml.Serialization.XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
    public System.DateTime CurrentTime;
    [System.Xml.Serialization.XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
    public uint RetryCount;
    [System.Xml.Serialization.XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
    public ParameterValueList ParameterList;
}

和我的代码

Inform inform = new Inform();
inform.Event = new EventList();

EventStruct es = new EventStruct();
es.EventCode = "0 BOOTSTRAP";
es.CommandKey = "";

我的问题是如何添加esinform.Event

以及如何序列化/反序列化类通知。

4

1 回答 1

0

你问题的第一部分。

inform.Event = es;

您问题的第二部分,这是我的一些代码,适用于您的情况。

反序列化:

XmlSerializer serializer = new XmlSerializer(typeof(Inform));
Inform ifnorm = null;
using (StreamReader sr = new StreamReader((FileName))
{
    inform = (Inform)serializer.Deserialize(sr)
}

我想你可以从这个链接到文档中找出序列化。

于 2013-03-14T13:57:26.960 回答