【问题标题】:Show an XML in C# [closed]在 C# 中显示 XML [关闭]
【发布时间】:2016-08-09 13:25:50
【问题描述】:

我的 Doc 变量中有一个 XMLDocument, 我需要向用户展示它。

 XmlDocument Doc = new XmlDocument();
 Doc.LoadXml(dataGridView1.SelectedCells[0].Value.ToString())

有没有类似 Doc.show() 之类的函数?

【问题讨论】:

  • 您希望如何显示 XML?您使用的是 WinForms、WPF、控制台应用程序吗?等

标签: c# .net xml


【解决方案1】:

当然没有。 XmlDocument 与您的表示层无关。选择您最喜欢的演示技术(WPF、WinForms、web...town crier 等等)并相应地进行渲染。

【讨论】:

  • 失望的选民不喜欢我的玩笑我猜 :)
  • 照片里是你吗?? :p
【解决方案2】:

您可以显示 XMLDocument 对象的 XML,例如,通过使用 XMLDocument 对象的 OuterXML 属性设置多行文本框的 Text 属性。

var xmlDocument = new XmlDocument();
xmlDocument.Load(@"C:\path\to\xmlFile.xml");

// For display on the console...
Console.WriteLine("XML: " + xmlDocument.OuterXML);

// For display in a WinForms TextBox control...
var text = new TextBox();
text.MultiLine = true;
text.Text = xmlDocument.OuterXML;

当然,您可以选择使用不同的控件或表示层技术来呈现 XML 内容,但我给出这个 WinForms TextBox 控件示例只是为了说明目的。

【讨论】:

    猜你喜欢
    • 2023-04-05
    • 2014-01-02
    • 1970-01-01
    • 2014-03-06
    • 2011-09-16
    • 2018-04-15
    • 1970-01-01
    • 2011-10-26
    相关资源
    最近更新 更多