public XmlDocument Export(List<CustomRedirect> redirects)
{
XmlDocument document = new XmlDocument();
XmlDeclaration xmlDeclaration = document.CreateXmlDeclaration("1.0", "UTF-8", null);
XmlElement root = document.DocumentElement;
document.InsertBefore(xmlDeclaration, root);
XmlElement redirectsElement = document.CreateElement(string.Empty, "redirects", string.Empty);
document.AppendChild(redirectsElement);
XmlElement urlsElement = document.CreateElement(string.Empty, "urls", string.Empty);
redirectsElement.AppendChild(urlsElement);
foreach (var redirect in redirects)
{
if (string.IsNullOrWhiteSpace(redirect.OldUrl) || string.IsNullOrWhiteSpace(redirect.NewUrl))
{
continue;
}
XmlElement urlElement = document.CreateElement(string.Empty, "url", string.Empty);
XmlElement oldElement = document.CreateElement(string.Empty, OLDURL, string.Empty);
oldElement.AppendChild(document.CreateTextNode(redirect.OldUrl.Trim()));
if (redirect.WildCardSkipAppend)
{
XmlAttribute wildCardAttribute = document.CreateAttribute(string.Empty, SKIPWILDCARD, string.Empty);
wildCardAttribute.Value = "true";
oldElement.Attributes.Append(wildCardAttribute);
}
XmlElement newElement = document.CreateElement(string.Empty, NEWURL, string.Empty);
newElement.AppendChild(document.CreateTextNode(redirect.NewUrl.Trim()));
urlElement.AppendChild(oldElement);
urlElement.AppendChild(newElement);
urlsElement.AppendChild(urlElement);
}
return document;
}