如何在文本框中显示所有值?有更多的价值观

时间:2016-06-28 07:13:39

标签: c#

XmlDocument xmlDoc = new XmlDocument(); 

 xmlDoc.Load(file);

  XmlNodeList name = xmlDoc.GetElementsByTagName("Name");

  XmlNodeList description = xmlDoc.GetElementsByTagName("Description");

XmlNodeList synonymname = xmlDoc.GetElementsByTagName("Synonym_Name");

 XmlNodeList typeflag = xmlDoc.GetElementsByTagName("Type_Flag");

XmlNodeList loopflag = xmlDoc.GetElementsByTagName("Loop_Flag");          

XmlNodeList pacgroups = xmlDoc.GetElementsByTagName("Pac_Groups");            

XmlNodeList grouid = xmlDoc.GetElementsByTagName("Grou_Id");

XmlNodeList funcid = xmlDoc.GetElementsByTagName("Func_Id");

1 个答案:

答案 0 :(得分:0)

var nodeNames = new [] { "Name", "Description", "Synonym_Name" };

var nodeContents = nodeNames
                       .Select(xmlDoc.GetElementsByTagName)
                       .Select(_ => _.Cast<XmlNode>())
                       .SelectMany(_ => _)
                       .Select(node => 
                       {
                            var stringBuilder = new StringBuilder();

                            var settings = new XmlWriterSettings { OmitXmlDeclaration = true, Indent = true };

                            using (var writer = XmlTextWriter.Create(stringBuilder, settings))
                            {
                                node.WriteTo(writer);

                                writer.Flush();

                                return stringBuilder.ToString();
                            }
                        });

var box = new System.Windows.Controls.TextBox();

box.Text = string.Concat(nodeContents);