我的代码生成的xml文件如下
<?xml version="1.0"?>
<DataClass xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<pathI>D:\POC\Input\2</pathI>
<pathO>D:\POC\Output</pathO>
<prefix>2_</prefix>
<frequency>25</frequency>
</DataClass><?xml version="1.0"?>
<DataClass xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<pathI>D:\POC\Input\3</pathI>
<pathO>D:\POC\Output</pathO>
<prefix>3_</prefix>
<frequency>33</frequency>
</DataClass>
我想向 xml 添加一个根元素,以便我可以进一步使用 xml 来填充数据网格视图。如果可能的话,还想从每个节点中消除标签..需要帮助
DataClass data = new DataClass();
data.pathI = txt_input.Text;
data.pathO = txt_Output.Text;
data.frequency = Convert.ToInt32(txt_freq.Text);
data.prefix = txt_prefix.Text;
XmlDocument doc = new XmlDocument();
XmlSerializer xs = new XmlSerializer(typeof(DataClass));
if (!File.Exists("Data.xml"))
{
using (FileStream fs = new FileStream("Data.xml", FileMode.Create))
{
xs.Serialize(fs, data);
fs.Close();
fs.Dispose();
MessageBox.Show("Data loaded to the xml");
}
}
else if (File.Exists("Data.xml"))
{
using (FileStream fs = new FileStream("Data.xml",FileMode.Append))
{
xs.Serialize(fs, data);
fs.Close();
fs.Dispose();
MessageBox.Show("Data loaded to the xml");
}
}