请教XML序列化问题
时间:2009-12-30
来源:互联网
<?xml version="1.0" encoding="UTF-8"?>
<RT_Component>
<ServiceProvidingInterface>
<DataSpecification>
<IN>true</IN>
<OUT>true</OUT>
<msg_type MESSAGE="message1" MAILBOX="[email protected]" SEMAPHORE="semaphore1"></msg_type>
</DataSpecification>
<ServiceSpecification service_name="service_name1" data_spec="data_spec1"></ServiceSpecification>
<ServiceProtocolSpecification>Service_Protocol_Specification1</ServiceProtocolSpecification>
</ServiceProvidingInterface>
<ServiceRequestingInterface>Service_Requesting_Interface1
</ServiceRequestingInterface>
<StateInterface>
<Status>Status1</Status>
<!--<State_Primitive create="create1">State_Primitive1</State_Primitive>-->
<State_Primitive>
<create>create1</create>
</State_Primitive>
</StateInterface>
<ConfigurationInterface>
<PerformanceConfigurationInterface>
<ServiceName>Service_Name1</ServiceName>
<TimeDescriptor>
<TimeType>
<cycle>cycle1</cycle>
</TimeType>
<ExecutionTime>2009-08-17T19:57:39.5+08:00</ExecutionTime>
<StartingTime>2009-08-27T19:57:39.5+08:00</StartingTime>
<TimePeriod>7 days</TimePeriod>
<TimeDeadline>6 hours</TimeDeadline>
</TimeDescriptor>
<PriorityDescriptor>PriorityDescriptor1</PriorityDescriptor>
</PerformanceConfigurationInterface>
<ResourceControlInterface>
<DeviceName>DeviceName1</DeviceName>
<Operation>Operation1</Operation>
</ResourceControlInterface>
<CompositionInterface>
<AggregationDescriptor>AggregationDescriptor1</AggregationDescriptor>
<SequenceDescriptor>SequenceDescriptor1</SequenceDescriptor>
<MutexDescriptor>MutexDescriptor1</MutexDescriptor>
</CompositionInterface>
</ConfigurationInterface>
</RT_Component>
对于上述XML文件,请在.NET 2005 中用C#对其序列化,因层次结构比较复杂,请各位帮忙。
烦请定义成如下格式,谢谢。
[XmlRootAttribute("PurchaseOrder", Namespace="http://www.cpandl.com",
IsNullable = false)]
public class PurchaseOrder
{
public Address ShipTo;
public string OrderDate;
/* The XmlArrayAttribute changes the XML element name
from the default of "OrderedItems" to "Items". */
[XmlArrayAttribute("Items")]
public OrderedItem[] OrderedItems;
public decimal SubTotal;
public decimal ShipCost;
public decimal TotalCost;
}
public class Address
{
/* The XmlAttribute instructs the XmlSerializer to serialize the Name
field as an XML attribute instead of an XML element (the default
behavior). */
[XmlAttribute]
public string Name;
public string Line1;
/* Setting the IsNullable property to false instructs the
XmlSerializer that the XML attribute will not appear if
the City field is set to a null reference. */
[XmlElementAttribute(IsNullable = false)]
public string City;
public string State;
public string Zip;
}
<RT_Component>
<ServiceProvidingInterface>
<DataSpecification>
<IN>true</IN>
<OUT>true</OUT>
<msg_type MESSAGE="message1" MAILBOX="[email protected]" SEMAPHORE="semaphore1"></msg_type>
</DataSpecification>
<ServiceSpecification service_name="service_name1" data_spec="data_spec1"></ServiceSpecification>
<ServiceProtocolSpecification>Service_Protocol_Specification1</ServiceProtocolSpecification>
</ServiceProvidingInterface>
<ServiceRequestingInterface>Service_Requesting_Interface1
</ServiceRequestingInterface>
<StateInterface>
<Status>Status1</Status>
<!--<State_Primitive create="create1">State_Primitive1</State_Primitive>-->
<State_Primitive>
<create>create1</create>
</State_Primitive>
</StateInterface>
<ConfigurationInterface>
<PerformanceConfigurationInterface>
<ServiceName>Service_Name1</ServiceName>
<TimeDescriptor>
<TimeType>
<cycle>cycle1</cycle>
</TimeType>
<ExecutionTime>2009-08-17T19:57:39.5+08:00</ExecutionTime>
<StartingTime>2009-08-27T19:57:39.5+08:00</StartingTime>
<TimePeriod>7 days</TimePeriod>
<TimeDeadline>6 hours</TimeDeadline>
</TimeDescriptor>
<PriorityDescriptor>PriorityDescriptor1</PriorityDescriptor>
</PerformanceConfigurationInterface>
<ResourceControlInterface>
<DeviceName>DeviceName1</DeviceName>
<Operation>Operation1</Operation>
</ResourceControlInterface>
<CompositionInterface>
<AggregationDescriptor>AggregationDescriptor1</AggregationDescriptor>
<SequenceDescriptor>SequenceDescriptor1</SequenceDescriptor>
<MutexDescriptor>MutexDescriptor1</MutexDescriptor>
</CompositionInterface>
</ConfigurationInterface>
</RT_Component>
对于上述XML文件,请在.NET 2005 中用C#对其序列化,因层次结构比较复杂,请各位帮忙。
烦请定义成如下格式,谢谢。
[XmlRootAttribute("PurchaseOrder", Namespace="http://www.cpandl.com",
IsNullable = false)]
public class PurchaseOrder
{
public Address ShipTo;
public string OrderDate;
/* The XmlArrayAttribute changes the XML element name
from the default of "OrderedItems" to "Items". */
[XmlArrayAttribute("Items")]
public OrderedItem[] OrderedItems;
public decimal SubTotal;
public decimal ShipCost;
public decimal TotalCost;
}
public class Address
{
/* The XmlAttribute instructs the XmlSerializer to serialize the Name
field as an XML attribute instead of an XML element (the default
behavior). */
[XmlAttribute]
public string Name;
public string Line1;
/* Setting the IsNullable property to false instructs the
XmlSerializer that the XML attribute will not appear if
the City field is set to a null reference. */
[XmlElementAttribute(IsNullable = false)]
public string City;
public string State;
public string Zip;
}
作者: seeusmile 发布时间: 2009-12-30
<RT_Component>
<ServiceProvidingInterface>
<DataSpecification>
<IN>true</IN>
<OUT>true</OUT>
<msg_type MESSAGE="message1" MAILBOX="[email protected]" SEMAPHORE="semaphore1"></msg_type>
</DataSpecification>
<ServiceSpecification service_name="service_name1" data_spec="data_spec1"></ServiceSpecification>
<ServiceProtocolSpecification>Service_Protocol_Specification1</ServiceProtocolSpecification>
</ServiceProvidingInterface>
<ServiceRequestingInterface>Service_Requesting_Interface1
</ServiceRequestingInterface>
<StateInterface>
<Status>Status1</Status>
<!--<State_Primitive create="create1">State_Primitive1</State_Primitive>-->
<State_Primitive>
<create>create1</create>
</State_Primitive>
</StateInterface>
<ConfigurationInterface>
<PerformanceConfigurationInterface>
<ServiceName>Service_Name1</ServiceName>
<TimeDescriptor>
<TimeType>
<cycle>cycle1</cycle>
</TimeType>
<ExecutionTime>2009-08-17T19:57:39.5+08:00</ExecutionTime>
<StartingTime>2009-08-27T19:57:39.5+08:00</StartingTime>
<TimePeriod>7 days</TimePeriod>
<TimeDeadline>6 hours</TimeDeadline>
</TimeDescriptor>
<PriorityDescriptor>PriorityDescriptor1</PriorityDescriptor>
</PerformanceConfigurationInterface>
<ResourceControlInterface>
<DeviceName>DeviceName1</DeviceName>
<Operation>Operation1</Operation>
</ResourceControlInterface>
<CompositionInterface>
<AggregationDescriptor>AggregationDescriptor1</AggregationDescriptor>
<SequenceDescriptor>SequenceDescriptor1</SequenceDescriptor>
<MutexDescriptor>MutexDescriptor1</MutexDescriptor>
</CompositionInterface>
</ConfigurationInterface>
</RT_Component>
<ServiceProvidingInterface>
<DataSpecification>
<IN>true</IN>
<OUT>true</OUT>
<msg_type MESSAGE="message1" MAILBOX="[email protected]" SEMAPHORE="semaphore1"></msg_type>
</DataSpecification>
<ServiceSpecification service_name="service_name1" data_spec="data_spec1"></ServiceSpecification>
<ServiceProtocolSpecification>Service_Protocol_Specification1</ServiceProtocolSpecification>
</ServiceProvidingInterface>
<ServiceRequestingInterface>Service_Requesting_Interface1
</ServiceRequestingInterface>
<StateInterface>
<Status>Status1</Status>
<!--<State_Primitive create="create1">State_Primitive1</State_Primitive>-->
<State_Primitive>
<create>create1</create>
</State_Primitive>
</StateInterface>
<ConfigurationInterface>
<PerformanceConfigurationInterface>
<ServiceName>Service_Name1</ServiceName>
<TimeDescriptor>
<TimeType>
<cycle>cycle1</cycle>
</TimeType>
<ExecutionTime>2009-08-17T19:57:39.5+08:00</ExecutionTime>
<StartingTime>2009-08-27T19:57:39.5+08:00</StartingTime>
<TimePeriod>7 days</TimePeriod>
<TimeDeadline>6 hours</TimeDeadline>
</TimeDescriptor>
<PriorityDescriptor>PriorityDescriptor1</PriorityDescriptor>
</PerformanceConfigurationInterface>
<ResourceControlInterface>
<DeviceName>DeviceName1</DeviceName>
<Operation>Operation1</Operation>
</ResourceControlInterface>
<CompositionInterface>
<AggregationDescriptor>AggregationDescriptor1</AggregationDescriptor>
<SequenceDescriptor>SequenceDescriptor1</SequenceDescriptor>
<MutexDescriptor>MutexDescriptor1</MutexDescriptor>
</CompositionInterface>
</ConfigurationInterface>
</RT_Component>
作者: chaff3539 发布时间: 2010-10-15
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28