AnalysisXML.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Xml;
  7. namespace BJShouXinYB_Demo
  8. {
  9. class AnalysisXML
  10. {
  11. public XmlDocument GetXmlDoc(string sXML)
  12. {
  13. XmlDocument xmlDoc = new XmlDocument();
  14. xmlDoc.LoadXml(sXML);
  15. return xmlDoc;
  16. }
  17. public XmlNode GetNodeFromPath(XmlNode oParentNode, string sPath)
  18. {
  19. XmlNode tmpNode = oParentNode.SelectNodes(sPath)[0];
  20. return tmpNode;
  21. }
  22. public bool CheckState(XmlDocument xmlDoc,out string OutMsg)
  23. {
  24. OutMsg = "";
  25. string sState = GetNodeFromPath(xmlDoc.DocumentElement, "state").Attributes["success"].InnerText;
  26. bool bRet = false;
  27. if (sState.Equals("true"))
  28. {
  29. bRet = true;
  30. //AddLog("调用返回状态:成功");
  31. }
  32. else
  33. {
  34. bRet = false;
  35. //AddLog("调用返回状态:失败");
  36. //读取错误信息
  37. XmlNodeList errNodes = GetNodeFromPath(xmlDoc.DocumentElement, "state").SelectNodes("error");
  38. string sErrNO = "", sErrMsg = "";
  39. for (int i = 0; i < errNodes.Count; i++)
  40. {
  41. if (errNodes[i].Attributes.Count > 0)
  42. {
  43. sErrNO = errNodes[i].Attributes["no"].InnerText;
  44. sErrMsg = errNodes[i].Attributes["info"].InnerText;
  45. //AddLog("调用返回错误:编号 [" + sErrNO + "] -- 描述 [" + sErrMsg + "]");
  46. }
  47. }
  48. //读取警告信息
  49. string sWarNO = "", sWarMsg = "";
  50. XmlNodeList warNodes = GetNodeFromPath(xmlDoc.DocumentElement, "state").SelectNodes("warning");
  51. for (int i = 0; i < warNodes.Count; i++)
  52. {
  53. if (warNodes[i].Attributes.Count > 0)
  54. {
  55. sWarNO = warNodes[i].Attributes["no"].InnerText;
  56. sWarMsg = warNodes[i].Attributes["info"].InnerText;
  57. //AddLog("调用返回警告:编号 [" + sWarNO + "] -- 描述 [" + sWarMsg + "]");
  58. }
  59. }
  60. OutMsg = "错误编号:" + sErrNO + "\n" +
  61. "错误信息:" + sErrMsg + "\n" +
  62. "警告编号:" + sWarNO + "\n" +
  63. "警告信息:" + sWarMsg + "\n";
  64. }
  65. //读取信息
  66. //XmlNodeList infNodes = GetNodeFromPath(xmlDoc.DocumentElement, "state").SelectNodes("information");
  67. //for (int i = 0; i < infNodes.Count; i++)
  68. //{
  69. // if (infNodes[i].Attributes.Count > 0)
  70. // {
  71. // string sInfNO = infNodes[i].Attributes["no"].InnerText;
  72. // string sInfMsg = infNodes[i].Attributes["info"].InnerText;
  73. // //AddLog("调用返回信息:编号 [" + sInfNO + "] -- 描述 [" + sInfMsg + "]");
  74. // }
  75. //}
  76. return bRet;
  77. }
  78. //public string bSucess(XmlDocument xmlDoc, string ItemName)
  79. //{
  80. // if (Node(ItemName) <> null)
  81. //}
  82. //public string GetXMLValue(string aXmlText, string FieldName)
  83. //{
  84. //}
  85. public bool CheckOutputState(XmlDocument xmlDoc)
  86. {
  87. string sState = GetNodeFromPath(xmlDoc.DocumentElement, "state").Attributes["success"].InnerText;
  88. bool bRet = false;
  89. if (sState.Equals("true"))
  90. {
  91. bRet = true;
  92. //AddLog("调用返回状态:成功");
  93. }
  94. else
  95. {
  96. bRet = false;
  97. //AddLog("调用返回状态:失败");
  98. }
  99. //读取错误信息
  100. XmlNodeList errNodes = GetNodeFromPath(xmlDoc.DocumentElement, "state").SelectNodes("error");
  101. for (int i = 0; i < errNodes.Count; i++)
  102. {
  103. if (errNodes[i].Attributes.Count > 0)
  104. {
  105. string sErrNO = errNodes[i].Attributes["no"].InnerText;
  106. string sErrMsg = errNodes[i].Attributes["info"].InnerText;
  107. //AddLog("调用返回错误:编号 [" + sErrNO + "] -- 描述 [" + sErrMsg + "]");
  108. }
  109. }
  110. //读取警告信息
  111. XmlNodeList warNodes = GetNodeFromPath(xmlDoc.DocumentElement, "state").SelectNodes("warning");
  112. for (int i = 0; i < warNodes.Count; i++)
  113. {
  114. if (warNodes[i].Attributes.Count > 0)
  115. {
  116. string sWarNO = warNodes[i].Attributes["no"].InnerText;
  117. string sWarMsg = warNodes[i].Attributes["info"].InnerText;
  118. //AddLog("调用返回警告:编号 [" + sWarNO + "] -- 描述 [" + sWarMsg + "]");
  119. }
  120. }
  121. //读取信息
  122. XmlNodeList infNodes = GetNodeFromPath(xmlDoc.DocumentElement, "state").SelectNodes("information");
  123. for (int i = 0; i < infNodes.Count; i++)
  124. {
  125. if (infNodes[i].Attributes.Count > 0)
  126. {
  127. string sInfNO = infNodes[i].Attributes["no"].InnerText;
  128. string sInfMsg = infNodes[i].Attributes["info"].InnerText;
  129. //AddLog("调用返回信息:编号 [" + sInfNO + "] -- 描述 [" + sInfMsg + "]");
  130. }
  131. }
  132. return bRet;
  133. }
  134. }
  135. }