Guest User

Untitled

a guest
Dec 8th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.16 KB | None | 0 0
  1. <Analysis Value="1" ReplyStatus="1" TestGroupCode="1">
  2. <AnaComment Type="1" Text="1" />
  3. <Lab AddressCode="1" Name="1" Address="1" />
  4. </Analysis>
  5.  
  6. <Analysis Value="1" ReplyStatus="1" TestGroupCode="1">
  7. <AnaComment Type="1" Text="1" />
  8. <Lab AddressCode="1" Name="1" Address="1" />
  9. </Analysis>
  10. <Analysis Value="2" ReplyStatus="2" TestGroupCode="2">
  11. <AnaComment Type="2" Text="2" />
  12. <Lab AddressCode="2" Name="2" Address="2" />
  13. </Analysis>
  14.  
  15. XDocument xdoc = XDocument.Load(xmlFile);
  16. foreach (XElement phoneElement in xdoc.Element("Sample").Elements("Analysis"))
  17. {
  18. XAttribute Value = phoneElement.Attribute("Value");
  19. XElement Lab = phoneElement.Element("Lab");
  20. XElement AnaComment = phoneElement.Element("AnaComment");
  21.  
  22. if (Value != null && AddressCode != null && AnaComment != null)
  23. {
  24. Console.WriteLine("Value: {0}", Value.Value);
  25. Console.WriteLine("Lab: {0}", AddressCode.Value);
  26. Console.WriteLine("AnaComment: {0}", AnaComment.Value);
  27. }
  28. Console.WriteLine();
  29. }
  30.  
  31. XmlDocument doc = new XmlDocument();
  32. doc.Load(xmlFile);
  33. XmlNodeList nodeList = doc.SelectNodes("//Sample/Analysis");
  34.  
  35. foreach (XmlElement node in nodeList)
  36. {
  37. string TestGroupCode = node.GetAttribute("TestGroupCode"), TestMethodCode = node.GetAttribute("TestMethodCode"), AnaName = node.GetAttribute("AnaName"),
  38. Value = node.GetAttribute("Value"), Unit = node.GetAttribute("Unit"), RefMin = node.GetAttribute("RefMin"), RefMax = node.GetAttribute("RefMax"),
  39. RefText = node.GetAttribute("RefText"), RefMark = node.GetAttribute("RefMark"), Finding = null;
  40.  
  41. XmlNodeList anaCommentList = node.SelectNodes("//Sample/Analysis/AnaComment");
  42. foreach (XmlElement childNode in anaCommentList)
  43. {
  44. //string Fin = childNode.GetAttribute("AnaComment");
  45. Finding += childNode.GetAttribute("Text");
  46. //Console.WriteLine(childNode.GetAttribute("Text"));
  47. //Не работает
  48. }
  49. }
  50.  
  51. static void Main()
  52. {
  53. XElement root = XElement.Load("<source file path>");
  54. foreach(XElement sample in root.Descendants("Sample"))
  55. {
  56. RecursiveOutput(sample);
  57. }
  58. Console.Read();
  59. }
  60. static void RecursiveOutput(XElement root)
  61. {
  62. foreach (XElement e in root.Elements())
  63. {
  64. Console.Write($"{e.Name} ");
  65. foreach (XAttribute a in e.Attributes())
  66. {
  67. Console.Write($"{a.Name} = {a.Value} ");
  68. }
  69. Console.WriteLine();
  70. RecursiveOutput(e);
  71. }
  72. }
  73.  
  74. static void FixedOutput(XElement root)
  75. {
  76. foreach (XElement e in root.Elements("Analysis"))
  77. {
  78. Console.Write($"{e.Name} ");
  79. foreach (XAttribute a in e.Attributes())
  80. {
  81. Console.Write($"{a.Name}={a.Value} ");
  82. }
  83. foreach (XElement ce in e.Elements())
  84. {
  85. foreach (XAttribute a in ce.Attributes())
  86. {
  87. Console.Write($"{a.Name}={a.Value} ");
  88. }
  89. }
  90. Console.WriteLine();
  91. }
  92. }
Add Comment
Please, Sign In to add comment