Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <Analysis Value="1" ReplyStatus="1" TestGroupCode="1">
- <AnaComment Type="1" Text="1" />
- <Lab AddressCode="1" Name="1" Address="1" />
- </Analysis>
- <Analysis Value="1" ReplyStatus="1" TestGroupCode="1">
- <AnaComment Type="1" Text="1" />
- <Lab AddressCode="1" Name="1" Address="1" />
- </Analysis>
- <Analysis Value="2" ReplyStatus="2" TestGroupCode="2">
- <AnaComment Type="2" Text="2" />
- <Lab AddressCode="2" Name="2" Address="2" />
- </Analysis>
- XDocument xdoc = XDocument.Load(xmlFile);
- foreach (XElement phoneElement in xdoc.Element("Sample").Elements("Analysis"))
- {
- XAttribute Value = phoneElement.Attribute("Value");
- XElement Lab = phoneElement.Element("Lab");
- XElement AnaComment = phoneElement.Element("AnaComment");
- if (Value != null && AddressCode != null && AnaComment != null)
- {
- Console.WriteLine("Value: {0}", Value.Value);
- Console.WriteLine("Lab: {0}", AddressCode.Value);
- Console.WriteLine("AnaComment: {0}", AnaComment.Value);
- }
- Console.WriteLine();
- }
- XmlDocument doc = new XmlDocument();
- doc.Load(xmlFile);
- XmlNodeList nodeList = doc.SelectNodes("//Sample/Analysis");
- foreach (XmlElement node in nodeList)
- {
- string TestGroupCode = node.GetAttribute("TestGroupCode"), TestMethodCode = node.GetAttribute("TestMethodCode"), AnaName = node.GetAttribute("AnaName"),
- Value = node.GetAttribute("Value"), Unit = node.GetAttribute("Unit"), RefMin = node.GetAttribute("RefMin"), RefMax = node.GetAttribute("RefMax"),
- RefText = node.GetAttribute("RefText"), RefMark = node.GetAttribute("RefMark"), Finding = null;
- XmlNodeList anaCommentList = node.SelectNodes("//Sample/Analysis/AnaComment");
- foreach (XmlElement childNode in anaCommentList)
- {
- //string Fin = childNode.GetAttribute("AnaComment");
- Finding += childNode.GetAttribute("Text");
- //Console.WriteLine(childNode.GetAttribute("Text"));
- //Не работает
- }
- }
- static void Main()
- {
- XElement root = XElement.Load("<source file path>");
- foreach(XElement sample in root.Descendants("Sample"))
- {
- RecursiveOutput(sample);
- }
- Console.Read();
- }
- static void RecursiveOutput(XElement root)
- {
- foreach (XElement e in root.Elements())
- {
- Console.Write($"{e.Name} ");
- foreach (XAttribute a in e.Attributes())
- {
- Console.Write($"{a.Name} = {a.Value} ");
- }
- Console.WriteLine();
- RecursiveOutput(e);
- }
- }
- static void FixedOutput(XElement root)
- {
- foreach (XElement e in root.Elements("Analysis"))
- {
- Console.Write($"{e.Name} ");
- foreach (XAttribute a in e.Attributes())
- {
- Console.Write($"{a.Name}={a.Value} ");
- }
- foreach (XElement ce in e.Elements())
- {
- foreach (XAttribute a in ce.Attributes())
- {
- Console.Write($"{a.Name}={a.Value} ");
- }
- }
- Console.WriteLine();
- }
- }
Add Comment
Please, Sign In to add comment