项目中调用第三方API,返回格式是XML字符串,需要将XML反序列化为对象,格式如下:

  1. <?xml version="1.0"?>
  2. <Response xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" totalCount="" resultCode="ABC" resultMessage="测试">
  3. <profile lastName="李" firstName="爽" dateOfBirth="XX0816" age="" gender="" address="浙江省 杭州富阳市 东州工业园区3号路1号杭州龙盛工贸有限公" email="htlslll@163.com" cellEmail="" socialMedia="" homePhone="" cellPhone="" contactabiltyMail="" contactabiltyEmail="" contactabiltyCellEmail="" contactabiltyHomePhone="" contactabiltyCellPhone="" contactabiltyText="" contactabiltySocialMedia="" vipLevel="" memberId="OC540C00016824" saAccount="" classa="小姐" homeStoreCode="OC54" />
  4. <purchaseHistory>
  5. <departmentPurchase totalLifeTimeSale="" totalTYAmount="" lastTxn="" totalTYUnitCnt="" firstTxn="">
  6. <department categoryName="D08" tyAmount="" tyUnitCnt="" />
  7. <department categoryName="D01" tyAmount="" tyUnitCnt="" />
  8. <department categoryName="D02" tyAmount="" tyUnitCnt="" />
  9. </departmentPurchase>
  10. <ratePurchase totalLyAmount="" totalLyRate="" totalTyAmount="" totalTyRate="" totalLifeTimeAmount="" totalLifeTimeRate="">
  11. <rate categoryName="Retail" lyAmount="" lyRate="" lyToDate="" tyAmount="" tyRate="" tyToDate="" lifeTimeAmount="" lifeTimeRate="" lyTyChange="" />
  12. </ratePurchase>
  13. <storeRatePurchase>
  14. <storeRate />
  15. </storeRatePurchase>
  16. </purchaseHistory>
  17. <vipStatus issueDate="" issueShop="OC54" ptsToUpgrade="" expiryDate="" upgradeShop="" ptsToRenew="" />
  18. <comments comment="第一场雪" />
  19. </Response>

按照这个格式我需要定义相应的对象来接收,定义如下:

  1. /// <summary>
  2. ///
  3. /// </summary>
  4. [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.34209")]
  5. [System.SerializableAttribute()]
  6. [System.ComponentModel.DesignerCategoryAttribute("code")]
  7. [System.Xml.Serialization.XmlRootAttribute(Namespace = "", IsNullable = false, ElementName = "Response")]
  8. public class Response
  9. {
  10. [System.Xml.Serialization.XmlAttributeAttribute()]
  11. public string totalCount { get; set; }
  12.  
  13. [System.Xml.Serialization.XmlAttributeAttribute()]
  14. public string resultCode { get; set; }
  15.  
  16. [System.Xml.Serialization.XmlAttributeAttribute()]
  17. public string resultMessage { get; set; }
  18.  
  19. [System.Xml.Serialization.XmlElementAttribute("profile", typeof(profile))]
  20. public profile profile { get; set; }
  21.  
  22. [System.Xml.Serialization.XmlElementAttribute("purchaseHistory", typeof(purchaseHistory))]
  23. public purchaseHistory purchaseHistory { get; set; }
  24.  
  25. [System.Xml.Serialization.XmlElementAttribute("vipStatus", typeof(vipStatus))]
  26. public vipStatus vipStatus { get; set; }
  27.  
  28. [System.Xml.Serialization.XmlElementAttribute("comments", typeof(comments))]
  29. public comments comments { get; set; }
  30. }
  31.  
  32. [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.34209")]
  33. [System.SerializableAttribute()]
  34. [System.ComponentModel.DesignerCategoryAttribute("code")]
  35. [System.Xml.Serialization.XmlRootAttribute(Namespace = "", IsNullable = true)]
  36. public class profile
  37. {
  38. [System.Xml.Serialization.XmlAttributeAttribute()]
  39. public string lastName { get; set; }
  40.  
  41. [System.Xml.Serialization.XmlAttributeAttribute()]
  42. public string firstName { get; set; }
  43.  
  44. [System.Xml.Serialization.XmlAttributeAttribute()]
  45. public string dateOfBirth { get; set; }
  46.  
  47. [System.Xml.Serialization.XmlAttributeAttribute()]
  48. public string age { get; set; }
  49.  
  50. [System.Xml.Serialization.XmlAttributeAttribute()]
  51. public string gender { get; set; }
  52.  
  53. [System.Xml.Serialization.XmlAttributeAttribute()]
  54. public string address { get; set; }
  55.  
  56. [System.Xml.Serialization.XmlAttributeAttribute()]
  57. public string email { get; set; }
  58.  
  59. [System.Xml.Serialization.XmlAttributeAttribute()]
  60. public string cellEmail { get; set; }
  61.  
  62. [System.Xml.Serialization.XmlAttributeAttribute()]
  63. public string socialMedia { get; set; }
  64.  
  65. [System.Xml.Serialization.XmlAttributeAttribute()]
  66. public string homePhone { get; set; }
  67.  
  68. [System.Xml.Serialization.XmlAttributeAttribute()]
  69. public string cellPhone { get; set; }
  70.  
  71. [System.Xml.Serialization.XmlAttributeAttribute()]
  72. public string contactabiltyMail { get; set; }
  73.  
  74. [System.Xml.Serialization.XmlAttributeAttribute()]
  75. public string contactabiltyEmail { get; set; }
  76.  
  77. [System.Xml.Serialization.XmlAttributeAttribute()]
  78. public string contactabiltyCellEmail { get; set; }
  79.  
  80. [System.Xml.Serialization.XmlAttributeAttribute()]
  81. public string contactabiltyHomePhone { get; set; }
  82.  
  83. [System.Xml.Serialization.XmlAttributeAttribute()]
  84. public string contactabiltyCellPhone { get; set; }
  85.  
  86. [System.Xml.Serialization.XmlAttributeAttribute()]
  87. public string contactabiltyText { get; set; }
  88.  
  89. [System.Xml.Serialization.XmlAttributeAttribute()]
  90. public string contactabiltySocialMedia { get; set; }
  91.  
  92. [System.Xml.Serialization.XmlAttributeAttribute()]
  93. public string vipLevel { get; set; }
  94.  
  95. [System.Xml.Serialization.XmlAttributeAttribute()]
  96. public string memberId { get; set; }
  97.  
  98. [System.Xml.Serialization.XmlAttributeAttribute()]
  99. public string saAccount { get; set; }
  100.  
  101. [System.Xml.Serialization.XmlAttributeAttribute()]
  102. public string classa { get; set; }
  103.  
  104. [System.Xml.Serialization.XmlAttributeAttribute()]
  105. public string homeStoreCode { get; set; }
  106. }
  107.  
  108. [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.34209")]
  109. [System.SerializableAttribute()]
  110. [System.ComponentModel.DesignerCategoryAttribute("code")]
  111. [System.Xml.Serialization.XmlRootAttribute(Namespace = "", IsNullable = true)]
  112. public class purchaseHistory
  113. {
  114.  
  115. [System.Xml.Serialization.XmlElementAttribute("departmentPurchase", typeof(departmentPurchase))]
  116. public departmentPurchase departmentPurchase { get; set; }
  117.  
  118. [System.Xml.Serialization.XmlElementAttribute("ratePurchase", typeof(ratePurchase))]
  119. public ratePurchase ratePurchase { get; set; }
  120.  
  121. [System.Xml.Serialization.XmlElementAttribute("storeRatePurchase", typeof(storeRatePurchase))]
  122. public storeRatePurchase storeRatePurchase { get; set; }
  123. }
  124.  
  125. [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.34209")]
  126. [System.SerializableAttribute()]
  127. [System.ComponentModel.DesignerCategoryAttribute("code")]
  128. [System.Xml.Serialization.XmlRootAttribute(Namespace = "", IsNullable = true)]
  129. public class departmentPurchase
  130. {
  131. [System.Xml.Serialization.XmlAttributeAttribute()]
  132. public string totalTYAmount { get; set; }
  133.  
  134. [System.Xml.Serialization.XmlAttributeAttribute()]
  135. public string totalTYUnitCnt { get; set; }
  136.  
  137. [System.Xml.Serialization.XmlAttributeAttribute()]
  138. public string firstTxn { get; set; }
  139.  
  140. [System.Xml.Serialization.XmlAttributeAttribute()]
  141. public string lastTxn { get; set; }
  142.  
  143. [System.Xml.Serialization.XmlAttributeAttribute()]
  144. public string totalLifeTimeSale { get; set; }
  145.  
  146. [System.Xml.Serialization.XmlElementAttribute("department", typeof(List<department>), Form = System.Xml.Schema.XmlSchemaForm.Unqualified, Order = )]
  147. public List<department> department { get; set; }
  148. }
  149.  
  150. [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.34209")]
  151. [System.SerializableAttribute()]
  152. [System.ComponentModel.DesignerCategoryAttribute("code")]
  153. [System.Xml.Serialization.XmlRootAttribute(Namespace = "", IsNullable = true)]
  154. public class department
  155. {
  156. [System.Xml.Serialization.XmlAttributeAttribute()]
  157. public string categoryName { get; set; }
  158.  
  159. [System.Xml.Serialization.XmlAttributeAttribute()]
  160. public string tyAmount { get; set; }
  161.  
  162. [System.Xml.Serialization.XmlAttributeAttribute()]
  163. public string tyUnitCnt { get; set; }
  164. }
  165.  
  166. [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.34209")]
  167. [System.SerializableAttribute()]
  168. [System.ComponentModel.DesignerCategoryAttribute("code")]
  169. [System.Xml.Serialization.XmlRootAttribute(Namespace = "", IsNullable = true)]
  170. public class ratePurchase
  171. {
  172. [System.Xml.Serialization.XmlAttributeAttribute()]
  173. public string totalLyAmount { get; set; }
  174.  
  175. [System.Xml.Serialization.XmlAttributeAttribute()]
  176. public string totalLyRate { get; set; }
  177.  
  178. [System.Xml.Serialization.XmlAttributeAttribute()]
  179. public string totalTyAmount { get; set; }
  180.  
  181. [System.Xml.Serialization.XmlAttributeAttribute()]
  182. public string totalTyRate { get; set; }
  183.  
  184. [System.Xml.Serialization.XmlAttributeAttribute()]
  185. public string totalLifeTimeAmount { get; set; }
  186.  
  187. [System.Xml.Serialization.XmlAttributeAttribute()]
  188. public string totalLifeTimeRate { get; set; }
  189.  
  190. [System.Xml.Serialization.XmlElementAttribute("rate", typeof(rate))]
  191. public rate rate { get; set; }
  192. }
  193.  
  194. [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.34209")]
  195. [System.SerializableAttribute()]
  196. [System.ComponentModel.DesignerCategoryAttribute("code")]
  197. [System.Xml.Serialization.XmlRootAttribute(Namespace = "", IsNullable = true)]
  198. public class rate
  199. {
  200. [System.Xml.Serialization.XmlAttributeAttribute()]
  201. public string categoryName { get; set; }
  202.  
  203. [System.Xml.Serialization.XmlAttributeAttribute()]
  204. public string lyAmount { get; set; }
  205.  
  206. [System.Xml.Serialization.XmlAttributeAttribute()]
  207. public string lyRate { get; set; }
  208.  
  209. [System.Xml.Serialization.XmlAttributeAttribute()]
  210. public string lyToDate { get; set; }
  211.  
  212. [System.Xml.Serialization.XmlAttributeAttribute()]
  213. public string tyAmount { get; set; }
  214.  
  215. [System.Xml.Serialization.XmlAttributeAttribute()]
  216. public string tyRate { get; set; }
  217. [System.Xml.Serialization.XmlAttributeAttribute()]
  218.  
  219. public string tyToDate { get; set; }
  220.  
  221. [System.Xml.Serialization.XmlAttributeAttribute()]
  222. public string lifeTimeAmount { get; set; }
  223.  
  224. [System.Xml.Serialization.XmlAttributeAttribute()]
  225. public string lifeTimeRate { get; set; }
  226.  
  227. [System.Xml.Serialization.XmlAttributeAttribute()]
  228. public string lyTyChange { get; set; }
  229.  
  230. }
  231.  
  232. [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.34209")]
  233. [System.SerializableAttribute()]
  234. [System.ComponentModel.DesignerCategoryAttribute("code")]
  235. [System.Xml.Serialization.XmlRootAttribute(Namespace = "", IsNullable = true)]
  236. public class storeRatePurchase
  237. {
  238. public string storeRate { get; set; }
  239. }
  240.  
  241. [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.34209")]
  242. [System.SerializableAttribute()]
  243. [System.ComponentModel.DesignerCategoryAttribute("code")]
  244. [System.Xml.Serialization.XmlRootAttribute(Namespace = "", IsNullable = true)]
  245. public class vipStatus
  246. {
  247. [System.Xml.Serialization.XmlAttributeAttribute()]
  248. public string issueDate { get; set; }
  249.  
  250. [System.Xml.Serialization.XmlAttributeAttribute()]
  251. public string issueShop { get; set; }
  252.  
  253. [System.Xml.Serialization.XmlAttributeAttribute()]
  254. public string ptsToUpgrade { get; set; }
  255.  
  256. [System.Xml.Serialization.XmlAttributeAttribute()]
  257. public string expiryDate { get; set; }
  258.  
  259. [System.Xml.Serialization.XmlAttributeAttribute()]
  260. public string upgradeShop { get; set; }
  261.  
  262. [System.Xml.Serialization.XmlAttributeAttribute()]
  263. public string ptsToRenew { get; set; }
  264. }
  265.  
  266. [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.34209")]
  267. [System.SerializableAttribute()]
  268. [System.ComponentModel.DesignerCategoryAttribute("code")]
  269. [System.Xml.Serialization.XmlRootAttribute(Namespace = "", IsNullable = true)]
  270. public class comments
  271. {
  272. [System.Xml.Serialization.XmlAttributeAttribute()]
  273. public string comment { get; set; }
  274. }

解析代码如下

  1. private static System.Xml.Serialization.XmlSerializer Serializer;
  2. /// <summary>
  3. /// 指定XML字符串序列化成对象
  4. /// </summary>
  5. /// <typeparam name="T"></typeparam>
  6. /// <param name="xml"></param>
  7. /// <returns></returns>
  8. public static T DeserializeForXml<T>(string xml) where T : class, new()
  9. {
  10. System.IO.StringReader stringReader = null;
  11. try
  12. {
  13. Serializer = Serializer ?? new XmlSerializer(typeof(T));
  14. stringReader = new StringReader(xml);
  15. T result = Serializer.Deserialize(stringReader) as T;
  16. return result;
  17. }
  18. finally
  19. {
  20. if ((stringReader != null))
  21. {
  22. stringReader.Dispose();
  23. }
  24. }
  25. }

调用方式:

var rpXML = AcxiomXMLHelper.DeserializeForXml<CustomerDetails.Response>(returnXML);

好了,接下来就出现了问题

departmentPurchase 下面的department始终是没有数据,调试好久都找不到问题出现在哪里。

尝试找解决的办法,先实例化一个Response对象序列化后写入文件,再将文件内容读出来反序列化出来

  1. Response response = new Response
  2. {
  3. totalCount = "",
  4. resultCode = "ABC",
  5. resultMessage = "测试",
  6. profile = new profile { lastName = "李", firstName = "爽", dateOfBirth = "XX0816", age = "", gender = "", address = "浙江省 杭州富阳市 东州工业园区3号路1号杭州龙盛工贸有限公", email = "htlslll@163.com", cellEmail = "", socialMedia = "", homePhone = "", cellPhone = "", contactabiltyMail = "", contactabiltyEmail = "", contactabiltyCellEmail = "", contactabiltyHomePhone = "", contactabiltyCellPhone = "", contactabiltyText = "", contactabiltySocialMedia = "", vipLevel = "", memberId = "OC540C00016824", saAccount = "", classa = "小姐", homeStoreCode = "OC54" },
  7. comments = new comments { comment = "第一场雪" },
  8. purchaseHistory = new purchaseHistory
  9. {
  10. departmentPurchase = new departmentPurchase
  11. {
  12. totalTYAmount = "",
  13. totalTYUnitCnt = "",
  14. firstTxn = "",
  15. lastTxn = "",
  16. totalLifeTimeSale = "",
  17. department = new List<department> {
  18. new department { categoryName = "D08", tyAmount = "", tyUnitCnt = "" },
  19. new department { categoryName = "D01", tyAmount = "", tyUnitCnt = "" },
  20. new department { categoryName = "D02", tyAmount = "", tyUnitCnt = "" }
  21. }
  22. },
  23. ratePurchase = new ratePurchase
  24. {
  25. totalLyAmount = "",
  26. totalLyRate = "",
  27. totalTyAmount = "",
  28. totalTyRate = "",
  29. totalLifeTimeAmount = "",
  30. totalLifeTimeRate = "",
  31. rate = new rate { categoryName = "Retail", lyAmount = "", lyRate = "", lyToDate = "", tyAmount = "", tyRate = "", tyToDate = "", lifeTimeAmount = "", lifeTimeRate = "", lyTyChange = "" }
  32. },
  33. storeRatePurchase = new storeRatePurchase { storeRate = string.Empty }
  34. },
  35. vipStatus = new vipStatus { issueDate = "", issueShop = "OC54", ptsToUpgrade = "", expiryDate = "", upgradeShop = "", ptsToRenew = "" }
  36. };
  37.  
  38. FileStream stream = new FileStream(@"d:\xmlFormat.xml", FileMode.Create);
  39. XmlSerializer xmlserilize = new XmlSerializer(typeof(Response));
  40. xmlserilize.Serialize(stream, response); stream.Close();
  41.  
  42. using (FileStream xmlStream = new FileStream(@"d:\xmlFormat.xml", FileMode.Open))
  43. {
  44. using (XmlReader xmlReader = XmlReader.Create(xmlStream))
  45. {
  46. XmlSerializer serializer = new XmlSerializer(typeof(Response));
  47. Response res = serializer.Deserialize(xmlReader) as Response;
  48. }
  49. }

代码中res是反序列化的结果,数据都正确。这就有点恼火了,怎么办呢?

比较我生成的文件和API返回的XML:

下面是我生成的XML格式

  1. <Response xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" totalCount="" resultCode="ABC" resultMessage="测试">
  2. <profile lastName="李" firstName="爽" dateOfBirth="XX0816" age="" gender="" address="浙江省 杭州富阳市 东州工业园区3号路1号杭州龙盛工贸有限公" email="htlslll@163.com" cellEmail="" socialMedia="" homePhone="" cellPhone="" contactabiltyMail="" contactabiltyEmail="" contactabiltyCellEmail="" contactabiltyHomePhone="" contactabiltyCellPhone="" contactabiltyText="" contactabiltySocialMedia="" vipLevel="" memberId="OC540C00016824" saAccount="" classa="小姐" homeStoreCode="OC54" />
  3. <purchaseHistory>
  4. <departmentPurchase totalLifeTimeSale="" totalTYAmount="" lastTxn="" totalTYUnitCnt="" firstTxn="">
  5. <department>
  6. <department categoryName="D08" tyAmount="" tyUnitCnt="" />
  7. <department categoryName="D01" tyAmount="" tyUnitCnt="" />
  8. <department categoryName="D02" tyAmount="" tyUnitCnt="" />
  9. </department>
  10. </departmentPurchase>
  11. <ratePurchase totalLyAmount="" totalLyRate="" totalTyAmount="" totalTyRate="" totalLifeTimeAmount="" totalLifeTimeRate="">
  12. <rate categoryName="Retail" lyAmount="" lyRate="" lyToDate="" tyAmount="" tyRate="" tyToDate="" lifeTimeAmount="" lifeTimeRate="" lyTyChange="" />
  13. </ratePurchase>
  14. <storeRatePurchase>
  15. <storeRate />
  16. </storeRatePurchase>
  17. </purchaseHistory>
  18. <vipStatus issueDate="" issueShop="OC54" ptsToUpgrade="" expiryDate="" upgradeShop="" ptsToRenew="" />
  19. <comments comment="第一场雪" />
  20. </Response>

仔细比对发现问题

在departmentPurchase 节点下我多了一层department节点,可我是按照接口的结果定义的对象啊

  1. [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.34209")]
  2. [System.SerializableAttribute()]
  3. [System.ComponentModel.DesignerCategoryAttribute("code")]
  4. [System.Xml.Serialization.XmlRootAttribute(Namespace = "", IsNullable = true)]
  5. public class departmentPurchase
  6. {
  7. [System.Xml.Serialization.XmlAttributeAttribute()]
  8. public string totalTYAmount { get; set; }
  9.  
  10. [System.Xml.Serialization.XmlAttributeAttribute()]
  11. public string totalTYUnitCnt { get; set; }
  12.  
  13. [System.Xml.Serialization.XmlAttributeAttribute()]
  14. public string firstTxn { get; set; }
  15.  
  16. [System.Xml.Serialization.XmlAttributeAttribute()]
  17. public string lastTxn { get; set; }
  18.  
  19. [System.Xml.Serialization.XmlAttributeAttribute()]
  20. public string totalLifeTimeSale { get; set; }
  21.  
  22. [System.Xml.Serialization.XmlElementAttribute("department", typeof(List<department>), Form = System.Xml.Schema.XmlSchemaForm.Unqualified, Order = )]
  23. public List<department> department { get; set; }
  24. }

怎么搞呢?在网上不停的找答案,最终都无解。但是没有放弃,答案也往往在快要放弃的时候出现

我尝试的修改了department的定义

修改前

  1. [System.Xml.Serialization.XmlElementAttribute("department", typeof(List<department>), Form = System.Xml.Schema.XmlSchemaForm.Unqualified, Order = )]
  2. public List<department> department { get; set; }

修改后

  1. [System.Xml.Serialization.XmlElementAttribute("department", typeof(department), Form = System.Xml.Schema.XmlSchemaForm.Unqualified, Order = )]
  2. public List<department> department { get; set; }

重新运行,奇迹出现

  1. <?xml version="1.0"?>
  2. <Response xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" totalCount="" resultCode="ABC" resultMessage="测试">
  3. <profile lastName="李" firstName="爽" dateOfBirth="XX0816" age="" gender="" address="浙江省 杭州富阳市 东州工业园区3号路1号杭州龙盛工贸有限公" email="htlslll@163.com" cellEmail="" socialMedia="" homePhone="" cellPhone="" contactabiltyMail="" contactabiltyEmail="" contactabiltyCellEmail="" contactabiltyHomePhone="" contactabiltyCellPhone="" contactabiltyText="" contactabiltySocialMedia="" vipLevel="" memberId="OC540C00016824" saAccount="" classa="小姐" homeStoreCode="OC54" />
  4. <purchaseHistory>
  5. <departmentPurchase totalLifeTimeSale="" totalTYAmount="" lastTxn="" totalTYUnitCnt="" firstTxn="">
  6. <department categoryName="D08" tyAmount="" tyUnitCnt="" />
  7. <department categoryName="D01" tyAmount="" tyUnitCnt="" />
  8. <department categoryName="D02" tyAmount="" tyUnitCnt="" />
  9. </departmentPurchase>
  10. <ratePurchase totalLyAmount="" totalLyRate="" totalTyAmount="" totalTyRate="" totalLifeTimeAmount="" totalLifeTimeRate="">
  11. <rate categoryName="Retail" lyAmount="" lyRate="" lyToDate="" tyAmount="" tyRate="" tyToDate="" lifeTimeAmount="" lifeTimeRate="" lyTyChange="" />
  12. </ratePurchase>
  13. <storeRatePurchase>
  14. <storeRate />
  15. </storeRatePurchase>
  16. </purchaseHistory>
  17. <vipStatus issueDate="" issueShop="OC54" ptsToUpgrade="" expiryDate="" upgradeShop="" ptsToRenew="" />
  18. <comments comment="第一场雪" />
  19. </Response>

问题解决。

原因就出在解析XML节点的

typeof(department) 与 typeof(List<department>)

记一次解析XML转对象的笔记的更多相关文章

  1. [C#]记一次解析XML转对象的笔记

    项目中调用第三方API,返回格式是XML字符串,需要将XML反序列化为对象,格式如下: <?xml version="1.0"?> <Response xmlns ...

  2. JAXB解析XML为对象

    JAXB支持注解将XML转化为对象,具体看一个简单的例子: <?xml version="1.0" encoding="utf-8"?> <A ...

  3. 解析xml的问题未解决

    工作上需要解析xml,目前的逻辑是:解析xml到对象中,然后对象再插入数据库.但这存在内存溢出的风险. 今天做的另外一件事是将循环用到工作上,暂时还没有测试,是否能保证程序的重启.有待观察 ##### ...

  4. Java高级特性 第14节 解析XML文档(2) - SAX 技术

    一.SAX解析XML文档 SAX的全称是Simple APIs for XML,也即XML简单应用程序接口.与DOM不同,SAX提供的访问模式是一种顺序模式,这是一种快速读写XML数据的方式.当使用S ...

  5. Android SAX解析XML

    本篇讲解一下SAX解析XML这种方式,首先来看一下它的基本介绍: SAX是一种以事件驱动的XML API,由它定义的事件流可以指定从解析器传到专门的处理程序的代码的XML结构,简单的讲,它是种解析速度 ...

  6. Java xml 操作(Dom4J修改xml   + xPath技术  + SAX解析 + XML约束)

    1 XML基础 1)XML的作用 1.1 作为软件配置文件 1.2 作为小型的"数据库" 2)XML语法(由w3c组织规定的) 标签: 标签名不能以数字开头,中间不能有空格,区分大 ...

  7. 利用Java反射机制完成XML到对象的解析

    对于一些小批量的数据,如果采用数据库来存取的话,未免有点大题小作,使用XML文件是个不错的方法,尤其是在一些Web应用中,经常需要缓存一部分数据,如果将这些数据形成XML文件,解析后放入一个Hasht ...

  8. webservice04#对象与xml转换-jaxb#Stax解析xml#新建修改xml

    1,Student类 package com.yangw.xml; import javax.xml.bind.annotation.XmlRootElement; @XmlRootElement / ...

  9. 遍历文件 创建XML对象 方法 python解析XML文件 提取坐标计存入文件

    XML文件??? xml即可扩展标记语言,它可以用来标记数据.定义数据类型,是一种允许用户对自己的标记语言进行定义的源语言. 里面的标签都是可以随心所欲的按照他的命名规则来定义的,文件名为roi.xm ...

随机推荐

  1. Win8下,以管理员身份启动VS项目

    之前一直是先以管理员身份启动VS,然后再打开项目的,比较麻烦,找了好久,总算有一个处理方案了 在Windows7下 通常使用修改属性的方式:在任意快捷方式上右击,选择属性,选择高级,选择以管理员身份启 ...

  2. Java生成、解析二维码

    今天遇到需求,使用Java生成二维码图片,网搜之后,大神们早就做过,个人总结一下. 目标:借助Google提供的ZXing Core工具包,使用Java语言实现二维码的生成和解析. 步骤如下: 1.m ...

  3. html中如何修改选中 用input做的搜索框 的边框颜色

    html中如何修改选中 用input做的搜索框 的边框颜色 如图,当我鼠标选中输入框时,内边框会变成蓝色 我的问题是: 1.如何把蓝色去掉? 2.如何改成别的颜色? 首先感谢 UI设计师提出的需求,解 ...

  4. javascript的方法

    1. decodeURIComponent() decodeURIComponent() 函数可对 encodeURIComponent() 函数编码的 URI 进行解码. 语法: decodeURI ...

  5. 关于Console控制台输出的玩法

    你在浏览网页的时候,是否注意过这些网页的控制台输出了什么? Console这种东西,其实一般只有前端工作者才会注意到.console在我们实际开发中可是个宝贝,他是各种error和warning的展示 ...

  6. JS 基础学习随想

    2012年就已经接触过了js,给我的印象:这是一门谈不上复杂的语言.大概这就是所谓的学的越浅,用的越少,觉得自己会的东西好像得更多吧!开始做基础练习题的时候觉得好像都十分简单.可是后来在做到对象数组的 ...

  7. c++STL排序算法注意事项

    关于算法中的比较函数 #include<iostream> #include<algorithm> using namespace std; int compare(doubl ...

  8. tornado学习 - TCPServer 实现聊天功能

    最近学习tornado框架,其中有很多值得学习的模块,鉴于某位学长的建议,也决定好好看看tornado.tcpserver. 关于TCP协议详细介绍可查阅wiki. 对于TCP服务器,基本的操作tor ...

  9. Spring+SpringMVC+MyBatis+easyUI整合基础篇(二)牛刀小试

    承接上文,该篇即为项目整合的介绍了. 废话不多说,先把源码和项目地址放上来,重点要写在前面. github地址为ssm-demo 你也可以先体验一下实际效果,点击这里就行啦 账号:admin 密码:1 ...

  10. 用react分页显示数据

    去年年底,尝试着用react写个组件化的页面! demo地址 里面有一个list页面弄了一下数据的分页展示 展示一下主要三个组件:父组件listBox.列表组件List.按钮组件PageButton ...