+ -
当前位置:首页 → 问答吧 → 请教XML序列化问题

请教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;  
  }  



作者: 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>

作者: chaff3539   发布时间: 2010-10-15