Guest User

Untitled

a guest
Dec 8th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.07 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. RecursiveOutput(root);
  55. Console.Read();
  56. }
  57. static void RecursiveOutput(XElement root)
  58. {
  59. foreach (XElement e in root.Elements())
  60. {
  61. Console.Write($"{e.Name} ");
  62. foreach (XAttribute a in e.Attributes())
  63. {
  64. Console.Write($"{a.Name} = {a.Value} ");
  65. }
  66. Console.WriteLine();
  67. RecursiveOutput(e);
  68. }
  69. }
  70.  
  71. static void FixedOutput(XElement root)
  72. {
  73. foreach (XElement e in root.Elements())
  74. {
  75. Console.Write($"{e.Name} ");
  76. foreach (XAttribute a in e.Attributes())
  77. {
  78. Console.Write($"{a.Name}={a.Value} ");
  79. }
  80. foreach (XElement ce in e.Elements())
  81. {
  82. foreach (XAttribute a in ce.Attributes())
  83. {
  84. Console.Write($"{a.Name}={a.Value} ");
  85. }
  86. }
  87. Console.WriteLine();
  88. }
  89. }
Add Comment
Please, Sign In to add comment