如何从listview生成xml文件?

时间:2022-01-05 09:58:42

I have a listview which contains data in Details view mode. So now my task is to take back up of data which ever i select from listview and create .xml file.I created a button "Export" and put a code to open "SaveFileDialog" in export_Click event handler.Now can anybody provide me the logic to achieve the task to create .xml file from the datas selected from listview in "export_Click" eventhandler . This is the bit of listview code used in the existing application.

我有一个listview,其中包含详细信息视图模式中的数据。所以现在我的任务是取回我从listview中选择的数据并创建.xml文件。我创建了一个按钮“Export”并放入一个代码在export_Click事件处理程序中打开“SaveFileDialog”。现在任何人都可以提供给我逻辑实现从“export_Click”事件处理程序中从listview中选择的数据创建.xml文件的任务。这是现有应用程序中使用的listview代码。

public class TrevoListView : System.Windows.Forms.ListView, IEditable
public class BaseLVItem : System.Windows.Forms.ListViewItem
      public TrevoListView ListView
      {
         get{ return t_listView; }
      }

If i iterate by using foreach loop , i will get each object like shown below, but i really stuck what logic i can do for creating xml?

如果我使用foreach循环迭代,我会得到如下所示的每个对象,但我真的坚持我可以做什么逻辑来创建xml?

foreach(BaseLVItem item in ListView.SelectedItems)

And one more thing these all datas displayed in listivew are from parent xml files. Server will serialize these xml and send it to GUI for displaying in controls like listview, we also have dataschema "TrevoDataSchema.xsd" Do i need to use XDocument or any other logic in side export_Click event handler ?

而且,listivew中显示的所有数据都来自父xml文件。服务器将序列化这些xml并将其发送到GUI以显示在listview之类的控件中,我们还有dataschema“TrevoDataSchema.xsd”我是否需要在侧面export_Click事件处理程序中使用XDocument或任何其他逻辑?

1 个解决方案

#1


1  

You could use XDocument from LINQ to XML and create a XML file from the ListItems, as shown in this answer https://*.com/a/4067146/64497

您可以使用从LINQ到XML的XDocument并从ListItems创建XML文件,如下面的答案https://*.com/a/4067146/64497

And use

并使用

XDocument.Save(filename)

To save the xml file, filename here is the name returned by the SaveFileDialog

要保存xml文件,filename这里是SaveFileDialog返回的名称

#1


1  

You could use XDocument from LINQ to XML and create a XML file from the ListItems, as shown in this answer https://*.com/a/4067146/64497

您可以使用从LINQ到XML的XDocument并从ListItems创建XML文件,如下面的答案https://*.com/a/4067146/64497

And use

并使用

XDocument.Save(filename)

To save the xml file, filename here is the name returned by the SaveFileDialog

要保存xml文件,filename这里是SaveFileDialog返回的名称