本文介绍了我可以对列表的结果进行排序&lt;&gt ;?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 大家好! 我是c#的新手,我想更加接近它。 我将结果从xml解析为新的xml结构后得到了结果。 这是从我的程序解析的: Hi everybody!I am new in c# and i wanna learn about it more closer.I have results after parse data from xml to new xml structure.This is parsed from my program:<start_conditions><finished quest_id="1941" /><finished quest_id="1943" /><finished quest_id="1944" /><finished quest_id="1945" /><finished quest_id="1946" /><unfinished quest_id="3941" /><unfinished quest_id="3947" /><unfinished quest_id="3950" /><unfinished quest_id="3953" /><unfinished quest_id="3956" /><unfinished quest_id="1974" /><notacquired quest_id="3941" /><notacquired quest_id="3947" /><notacquired quest_id="3950" /><notacquired quest_id="3953" /><notacquired quest_id="3956" /><notacquired quest_id="1974" /></start_conditions> 但我希望结果必须如下: But i want results must be like this:<start_conditions> <finished quest_id="1941"/> <unfinished>3941</unfinished> <noacquired>3941</noacquired> </start_conditions> <start_conditions> <finished quest_id="1943"/> <unfinished>3947</unfinished> <noacquired>3947</noacquired> </start_conditions> <start_conditions> <finished quest_id="1944"/> <unfinished>3950</unfinished> <noacquired>3950</noacquired> </start_conditions> <start_conditions> <finished quest_id="1945"/> <unfinished>3953</unfinished> <noacquired>3953</noacquired> </start_conditions> <start_conditions> <finished quest_id="1946"/> <unfinished>3956</unfinished> <noacquired>3956</noacquired> </start_conditions> <start_conditions> <unfinished>1974</unfinished> <noacquired>1974</noacquired> </start_conditions> 这是我的主要代码: and there's my main code:var questConds = GetConditions(quest, "finished_quest_cond"); if (questConds.Count > 0) { if (q.start_conditions == null) q.start_conditions = new QuestStartCondition(); q.start_conditions.finishedQuestSteps = new List<QuestStep>(); for (int i = 0; i < questConds.Count; i++) { q.start_conditions.finishedQuestSteps.Add(questConds[i].questSteps[0]); } } questConds = GetConditions(quest, "unfinished_quest_cond"); if (questConds.Count > 0) { if (q.start_conditions == null) q.start_conditions = new QuestStartCondition(); q.start_conditions.unfinishedQuestSteps = new List<QuestStep>(); for (int i = 0; i < questConds.Count; i++) { q.start_conditions.unfinishedQuestSteps.Add(questConds[i].questSteps[0]); } } questConds = GetConditions(quest, "noacquired_quest_cond"); if (questConds.Count > 0) { if (q.start_conditions == null) q.start_conditions = new QuestStartCondition(); q.start_conditions.notAcquiredQuestSteps = new List<QuestStep>(); for (int i = 0; i < questConds.Count; i++) { q.start_conditions.notAcquiredQuestSteps.Add(questConds[i].questSteps[0]); } } 我不知道我需要什么...如果你有解决方案,请帮助和我非常乐意为您提供帮助。 最佳方面 Nism! I dont know what i need todo... If you have solution please help and im very pleasure for your help. best regardNism!推荐答案 看看这是否有助于您入门:...粘贴到WinForms项目MainWindow:运行方法'testReadXML()...在Console中观察输出...然后弄清楚如何使用用于创建新XML实例的内容:See if this helps you get started: ... paste into WinForms project MainWindow: run Method 'testReadXML() ... observe output in Console ... then figure out how to use the content to create a new XML instance:// requiredusing System;using System.Collections.Generic;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using System.Xml.Linq;private string xml = @"<start_conditions> <finished quest_id="" 1941="" /> <finished quest_id="" 1943="" /> <finished quest_id="" 1944="" /> <finished quest_id="" 1945="" /> <finished quest_id="" 1946="" /> <unfinished quest_id="" 3941="" /> <unfinished quest_id="" 3947="" /> <unfinished quest_id="" 3950="" /> <unfinished quest_id="" 3953="" /> <unfinished quest_id="" 3956="" /> <unfinished quest_id="" 1974="" /> <notacquired quest_id="" 3941="" /> <notacquired quest_id="" 3947="" /> <notacquired quest_id="" 3950="" /> <notacquired quest_id="" 3953="" /> <notacquired quest_id="" 3956="" /> <notacquired quest_id="" 1974="" /></start_conditions>";private void readXML(string theXML){ XDocument xdoc = XDocument.Parse(theXML); foreach (XElement element in xdoc.Descendants("start_conditions")) { var elem1 = element.Elements("finished").ToList(); var elem2 = element.Elements("unfinished").ToList(); var elem3 = element.Elements("notacquired").ToList(); StringBuilder sb = new StringBuilder("<start_conditions>"); sb.AppendLine(); for (int i = 0; i < elem1.Count; i++) { sb.Append(elem1[i]); sb.Append(elem2[i]); sb.Append(elem3[i]); sb.AppendLine(); } if (elem1.Count < elem2.Count) { for (int i = elem1.Count; i < elem2.Count; i++) { sb.Append(elem2[i]); sb.Append(elem3[i]); sb.AppendLine(); } } sb.Append("</start_conditions>"); Console.WriteLine(sb.ToString()); }}private testReadXML(){ readXML(xml);} 这篇关于我可以对列表的结果进行排序&lt;&gt ;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-17 01:18