.net解释xml



格式:我们取ContainerEvent的数据

[html]  view plain  copy
  1.  <?xml version="1.0" ?>   
  2. <Master xmlns:xsi="http://www.w3.org/2001/XMLSchemainstance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">  
  3.  <OnBoardDate>20130225T06:00:00</OnBoardDate>   
  4.  <PortOfLoading>CNDLC</PortOfLoading>   
  5.  <ETA>20130317T17:45:00</ETA>   
  6.  <ATA xsi:nil="true" />   
  7.  <ManifestQuantity>3720</ManifestQuantity>   
  8. <Containers>  
  9. <Container>  
  10.  <ContainerNo>OOLU7246170</ContainerNo>   
  11.  <Weight>18048.000 KGS</Weight>   
  12.  <Quantity>3720 Carton</Quantity>   
  13.  <CurrentStatus>Container Returned to Carrier</CurrentStatus>   
  14.  <Date>20130327T23:58:00</Date>   
  15.  <LocationName>Equipment For Sale/offhire</LocationName>   
  16.  <EDICenterRecevedDate xsi:nil="true" />   
  17.  <SEQ xsi:nil="true" />   
  18. <events>  
  19. <ContainerEvent>  
  20.  <Time>20130317T17:45:00</Time>   
  21.  <EventDesc>Vessel Arrived</EventDesc>   
  22.  <Location>Tacoma, Tacoma, Pierce, Washington, United States</Location>   
  23.  <Mode />   
  24.  <Facility>Port of Discharge</Facility>   
  25.  <Remarks />   
  26.  </ContainerEvent>  
  27. <ContainerEvent>  
  28.  <Time>20130304T08:00:00</Time>   
  29.  <EventDesc>Vessel Departed</EventDesc>   
  30.  <Location>Busan, Busan, South Korea</Location>   
  31.  <Mode />   
  32.  <Facility>Port of Transshipment</Facility>   
  33.  <Remarks />   
  34.  </ContainerEvent>  
  35. <ContainerEvent>  
  36.  <Time>20130219T12:04:00</Time>   
  37.  <EventDesc>Container Picked Up</EventDesc>   
  38.  <Location>Yungtong Depot, Dalian, Liaoning, China</Location>   
  39.  <Mode>Truck</Mode>   
  40.  <Facility />   
  41.  <Remarks>Empty Container</Remarks>   
  42.  </ContainerEvent>  
  43.  </events>  
  44.  </Container>  
  45.  </Containers>  
  46.  </Master>  

[csharp]  view plain  copy
  1. public JsonResult GetXMLData()   
  2.        {  
  3.            try  
  4.            {  
  5.                string xmlstr="....";  
  6.                StringReader reader = new StringReader(xmlstr);  
  7.                IList<ContainerEvent> products = new List<ContainerEvent>();  
  8.                var serializer = new XmlSerializer(typeof(Master));  
  9.                var items = (Master)serializer.Deserialize(reader);  
  10.                return Json(items.cts.ct.events.Items);  
  11.            }  
  12.            catch (Exception ) {  
  13.                return Json("查询错误!");  
  14.            }  
  15.        }  

model:

[csharp]  view plain  copy
  1. [Serializable]   
  2.    public class ContainerEvent  
  3.    {  
  4.        //[XmlAttribute(AttributeName = "Time")]  
  5.        public DateTime Time { getset; }  
  6.        //[XmlAttribute(AttributeName = "EventDesc")]  
  7.        public string EventDesc { getset; }  
  8.        //[XmlAttribute(AttributeName = "Location")]  
  9.        public string Location { getset; }  
  10.      //  [XmlAttribute(AttributeName = "Mode")]  
  11.        public string Mode { getset; }  
  12.       // [XmlAttribute(AttributeName = "Facility")]  
  13.        public string Facility { getset; }  
  14.      //  [XmlAttribute(AttributeName = "Remarks")]  
  15.        public string Remarks { getset; }  
  16.    }  
  17.   
  18.    [XmlRoot("Master")] //XmlRoot必须描述根元素  
  19.    public class Master  
  20.    {  
  21.        [XmlElement("Containers")]  
  22.        public Containers cts { getset; }  
  23.    }  
  24.   
  25.   
  26.    public class Containers  
  27.    {  
  28.        [XmlElement("Container")]  
  29.        public Container ct { getset; }  
  30.    }  
  31.   
  32.    public class Container   
  33.    {  
  34.        [XmlElement("events")]  
  35.        public events events { getset; }  
  36.    }  
  37.   
  38.    public class events   
  39.    {  
  40.        [XmlElement("ContainerEvent")]  
  41.        public ContainerEvent[] Items { getset; }  
  42.    }  

http://www.bdqn.cn/news/201312/12290.shtml

http://blog.youkuaiyun.com/bdstjk/article/details/7210742

http://blog.youkuaiyun.com/bdstjk/article/details/7211086


格式:我们取ContainerEvent的数据

[html]  view plain  copy
  1.  <?xml version="1.0" ?>   
  2. <Master xmlns:xsi="http://www.w3.org/2001/XMLSchemainstance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">  
  3.  <OnBoardDate>20130225T06:00:00</OnBoardDate>   
  4.  <PortOfLoading>CNDLC</PortOfLoading>   
  5.  <ETA>20130317T17:45:00</ETA>   
  6.  <ATA xsi:nil="true" />   
  7.  <ManifestQuantity>3720</ManifestQuantity>   
  8. <Containers>  
  9. <Container>  
  10.  <ContainerNo>OOLU7246170</ContainerNo>   
  11.  <Weight>18048.000 KGS</Weight>   
  12.  <Quantity>3720 Carton</Quantity>   
  13.  <CurrentStatus>Container Returned to Carrier</CurrentStatus>   
  14.  <Date>20130327T23:58:00</Date>   
  15.  <LocationName>Equipment For Sale/offhire</LocationName>   
  16.  <EDICenterRecevedDate xsi:nil="true" />   
  17.  <SEQ xsi:nil="true" />   
  18. <events>  
  19. <ContainerEvent>  
  20.  <Time>20130317T17:45:00</Time>   
  21.  <EventDesc>Vessel Arrived</EventDesc>   
  22.  <Location>Tacoma, Tacoma, Pierce, Washington, United States</Location>   
  23.  <Mode />   
  24.  <Facility>Port of Discharge</Facility>   
  25.  <Remarks />   
  26.  </ContainerEvent>  
  27. <ContainerEvent>  
  28.  <Time>20130304T08:00:00</Time>   
  29.  <EventDesc>Vessel Departed</EventDesc>   
  30.  <Location>Busan, Busan, South Korea</Location>   
  31.  <Mode />   
  32.  <Facility>Port of Transshipment</Facility>   
  33.  <Remarks />   
  34.  </ContainerEvent>  
  35. <ContainerEvent>  
  36.  <Time>20130219T12:04:00</Time>   
  37.  <EventDesc>Container Picked Up</EventDesc>   
  38.  <Location>Yungtong Depot, Dalian, Liaoning, China</Location>   
  39.  <Mode>Truck</Mode>   
  40.  <Facility />   
  41.  <Remarks>Empty Container</Remarks>   
  42.  </ContainerEvent>  
  43.  </events>  
  44.  </Container>  
  45.  </Containers>  
  46.  </Master>  

[csharp]  view plain  copy
  1. public JsonResult GetXMLData()   
  2.        {  
  3.            try  
  4.            {  
  5.                string xmlstr="....";  
  6.                StringReader reader = new StringReader(xmlstr);  
  7.                IList<ContainerEvent> products = new List<ContainerEvent>();  
  8.                var serializer = new XmlSerializer(typeof(Master));  
  9.                var items = (Master)serializer.Deserialize(reader);  
  10.                return Json(items.cts.ct.events.Items);  
  11.            }  
  12.            catch (Exception ) {  
  13.                return Json("查询错误!");  
  14.            }  
  15.        }  

model:

[csharp]  view plain  copy
  1. [Serializable]   
  2.    public class ContainerEvent  
  3.    {  
  4.        //[XmlAttribute(AttributeName = "Time")]  
  5.        public DateTime Time { getset; }  
  6.        //[XmlAttribute(AttributeName = "EventDesc")]  
  7.        public string EventDesc { getset; }  
  8.        //[XmlAttribute(AttributeName = "Location")]  
  9.        public string Location { getset; }  
  10.      //  [XmlAttribute(AttributeName = "Mode")]  
  11.        public string Mode { getset; }  
  12.       // [XmlAttribute(AttributeName = "Facility")]  
  13.        public string Facility { getset; }  
  14.      //  [XmlAttribute(AttributeName = "Remarks")]  
  15.        public string Remarks { getset; }  
  16.    }  
  17.   
  18.    [XmlRoot("Master")] //XmlRoot必须描述根元素  
  19.    public class Master  
  20.    {  
  21.        [XmlElement("Containers")]  
  22.        public Containers cts { getset; }  
  23.    }  
  24.   
  25.   
  26.    public class Containers  
  27.    {  
  28.        [XmlElement("Container")]  
  29.        public Container ct { getset; }  
  30.    }  
  31.   
  32.    public class Container   
  33.    {  
  34.        [XmlElement("events")]  
  35.        public events events { getset; }  
  36.    }  
  37.   
  38.    public class events   
  39.    {  
  40.        [XmlElement("ContainerEvent")]  
  41.        public ContainerEvent[] Items { getset; }  
  42.    }  

http://www.bdqn.cn/news/201312/12290.shtml

http://blog.youkuaiyun.com/bdstjk/article/details/7210742

http://blog.youkuaiyun.com/bdstjk/article/details/7211086


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值