uhaciogullari / SimpleMvcSitemap

A minimalist library for creating sitemap files inside ASP.NET MVC and ASP.NET Core MVC applications
MIT License
128 stars 39 forks source link

Write To Physical Xml In MVC Core #20

Closed Milad-Darvishi closed 7 years ago

Milad-Darvishi commented 7 years ago

How Can I get Write nodes in xml file?

uhaciogullari commented 7 years ago

Hi @iranidesign

It's not supported out of the box. You can fork the project and modify the XmlSerializer class and output to a file. I don't see a common use case here so I am not planning to implement it for now.

BenjaminMichaelis commented 2 years ago

Way later than from when this issue was opened but I needed this feature, so I forked this and added this feature to write to a physical Xml file: https://github.com/BenjaminMichaelis/DotnetSitemapGenerator The nuget package is here to install to your project is here: https://www.nuget.org/packages/DotnetSitemapGenerator

An example usage is:

IXmlSerializer sitemapProvider = new XmlSerializer();
List<SitemapNode> nodes = new(); // Add in your nodes here

// third parameter (true in this case) is used to mark whether the outputed xml file should
// be formatted in a way that it is easily readable by human eyes which is
// helpful with visual validation
sitemapProvider.Serialize(new SitemapModel(nodes), xmlSavePath, true);

as is documented in the readme