Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
311 views
in Technique[技术] by (71.8m points)

c# - 使用XML Serializer和TextWriter将节点附加到XML根节点(Append node to XML root node using XML Serializer And TextWriter)

Hi is there any way to append data to an existing XML document using XML serializer.

(您好,可以使用XML序列化器将数据附加到现有XML文档中。)

I am currently doing it like this

(我目前正在这样做)

string filePath = "Data.xml";
var serializer = new XmlSerializer(typeof(Event));
extWriter writer = new StreamWriter(filePath, true);
serializer.Serialize(writer, event);

This way adds the element like a root node instead of a child node...I also used LINQ to XML that way worked fine but that's way seems hardcoded, is there any way to achieve it using this method.

(这种方式添加了像根节点而不是子节点这样的元素...我也使用LINQ到XML,这种方式可以正常工作,但是这种方式似乎是硬编码的,有什么方法可以使用这种方法来实现。)

  ask by mike oconner translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...