D
D
Deka0072019-08-03 11:56:50
.NET
Deka007, 2019-08-03 11:56:50

How to write data to one xml file without overwriting?

There is an array with links to rss sites, I load the xml structure from the links, but I can’t load all the xml structures from all the links of the array, because it overwrites them, as a result I load only one structure from one link, and other links remain in the array.

string[] rsslinks = { "https://www.e-ir.info/category/blogs/feed/", "https://www.reddit.com/r/worldnews/.rss"};
 OnGetFeed(rsslinks);

 void OnGetFeed(string[] uri)
            {
                foreach (string url in uri)
                {
                    string writePath = @"D:\RssFeed\RSS_feed.xml";
                    
                    XmlDocument doc = new XmlDocument();
                    doc.Load(url);
                    
                    doc.Save(writePath);
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Gaydak, 2019-08-03
@Deka007

so you create a NEW XmlDocument object in each iteration of the foreach loop
doc = new XmlDocument();
Take the creation out of the loop. and do not overwrite, but supplement)) although I feel you want not just a text in a row, but to preserve the xml structure, then parse each file / link for you and collect what you need into one of your own.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question