【发布时间】:2021-06-14 13:41:38
【问题描述】:
我需要使用 C# 在现有文件中添加新项目,请提供最佳逻辑来使用 C#。 下面是我的 XML 文件(输入)=
<?xml version="1.0" encoding="UTF-8"?>
<FileSetting xmlns="http://ltsc.ieee.org/xsd/LOM" xmlns:xs="http://www.M1.org/2001/XMLSchema">
<Files>
<File Section="Section 1" Method="Complete" Location="Total 1">
<Columns>
<Profile Method="DataCollection" Item="All" />
</Columns>
</File>
<!-- <File Section="Section 2" Method="Complete" Location="Total 2">
<Columns>
<Profile Method= "DataCollection" Item="All"/>
</Columns>
</File> -->
<File Section="Section 3" Method="Complete" Location="Main">
<Columns>
<Profile Method="DataCollection" Item="All" />
</Columns>
</File>
</Files>
</FileSetting>
在我现有的 XML 文件中,我想在 Files 下添加新的 File 项,所以 我期望输出为=
<?xml version="1.0" encoding="UTF-8"?>
<FileSetting xmlns="http://ltsc.ieee.org/xsd/LOM" xmlns:xs="http://www.M1.org/2001/XMLSchema">
<Files>
<File Section="Section 1" Method="Complete" Location="Total 1">
<Columns>
<Profile Method="DataCollection" Item="All" />
</Columns>
</File>
<!-- <File Section="Section 2" Method="Complete" Location="Total 2">
<Columns>
<Profile Method= "DataCollection" Item="All"/>
</Columns>
</File> -->
<File Section="Section 3" Method="Complete" Location="Main">
<Columns>
<Profile Method="DataCollection" Item="All" />
</Columns>
</File>
<File Section="Section 4" Method="NotComplete" Location="Test5">
<Columns>
<Profile Method="DataCollecter" Item="Partial" />
</Columns>
</File>
</Files>
</FileSetting>
谁能提供在 C# 中执行此操作的最佳逻辑?
提前致谢
【问题讨论】:
标签: c# xml linq-to-xml xmldocument