示例#1
0
        /// <summary>
        /// Create and populate a redirect node, then append it to the xml document.
        /// </summary>
        /// <param name="document"></param>
        /// <param name="urlPair"></param>
        /// <param name="rewriteMaps"></param>
        /// <param name="count"></param>
        static void AddRedirect(XmlDocument document, URLPair urlPair, XmlNode rewriteMaps, ref int count)
        {
            XmlNode node = document.CreateNode("element", "add", "");

            XmlAttribute keyAttr = document.CreateAttribute("key");

            keyAttr.Value = urlPair.OldURL;

            XmlAttribute valueAttr = document.CreateAttribute("value");

            valueAttr.Value = urlPair.NewURL;

            node.Attributes.Append(keyAttr);
            node.Attributes.Append(valueAttr);

            rewriteMaps.AppendChild(node);
            count++;
            Console.WriteLine("Redirect added");
        }
示例#2
0
 /// <summary>
 /// Uses an XPath query to determine whether a redirect already exists in the XML file.
 /// </summary>
 /// <param name="doc"></param>
 /// <param name="urlPair"></param>
 /// <returns></returns>
 static bool RedirectExists(XmlDocument doc, URLPair urlPair)
 {
     return(doc.SelectSingleNode($"//add[@key='{urlPair.OldURL}' and @value='{urlPair.NewURL}']") != null);
 }