本文介绍了附加到现有的xml文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想写一个XML文件,但是,在某些情况下,我可能需要添加到一个包含封闭根元素的现有文件中.任何想法如何进行修改文件.

C#

I would like to write to an XML file, however, it might be the case that I might need to add to an existing file, which includes a closing root element. Any idea how to go about amending the file.

C#

string _path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
            _path = _path.Substring(6, _path.Length - 6);
            string _file =  _path + "\\article.xml";

            FileStream fs = new FileStream(_file, FileMode.Create);
            XmlTextWriter w = new XmlTextWriter(fs, null);



article.xml



article.xml

<pre lang="xml"><?xml version="1.0" encoding="ISO-8859-1"?>
<articles>
    <article>
      <timestamp>24/08/2010 15:12</timestamp>
      <subject> subject</subject>
      <body>this is a test</body>
      <entryID>000001</entryID>
      <deleted>No</deleted>
      <tag>tag1,tag2</tag>
    </article>
    <article>
      <timestamp>24/08/2010 15:13</timestamp>
      <subject> subject 2</subject>
      <body>this is a test</body>
      <entryID>000001</entryID>
      <deleted>No</deleted>
      <tag>tag1,tag2</tag>
    </article>
</articles>




:confused:


注意:注意,




:confused:


NOTE: It''s noted that the sequence following the

tag consisting of "<pre lang="xml">&lt;?" is not rendered as text within this forum.

推荐答案


这篇关于附加到现有的xml文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-26 21:22
查看更多