Beispiel #1
0
        /// <summary>
        /// Replace the links searching for any anchor (a) or image (img) element.
        /// The delegate (callback method) passed is used to generate the new link based on the previous value.
        /// </summary>
        public void ReplaceLinks(ReplaceLinkHandler replaceMethod)
        {
            System.Xml.XmlNodeList anchors = mDoc.SelectNodes("//a");
            System.Xml.XmlNodeList images  = mDoc.SelectNodes("//img");

            foreach (System.Xml.XmlElement element in anchors)
            {
                string href = element.GetAttribute("href");

                string newUrl;
                replaceMethod(href, out newUrl);
                element.SetAttribute("href", newUrl);
            }

            foreach (System.Xml.XmlElement element in images)
            {
                string href = element.GetAttribute("src");

                string newUrl;
                replaceMethod(href, out newUrl);
                element.SetAttribute("src", newUrl);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Replace the links searching for any anchor (a) or image (img) element.
        /// The delegate (callback method) passed is used to generate the new link based on the previous value.
        /// </summary>
        public void ReplaceLinks(ReplaceLinkHandler replaceMethod)
        {
            if (this._xmlDoc == null)
            {
                throw new ArgumentNullException("xmlDoc");
            }
            if (replaceMethod == null)
            {
                throw new ArgumentNullException("replaceMethod");
            }
            //
            XmlNodeList anchors = this._xmlDoc.SelectNodes("//a");
            XmlNodeList images  = this._xmlDoc.SelectNodes("//img");

            string href, newUrl;

            if (anchors != null)
            {
                foreach (XmlElement element in anchors)
                {
                    href = element.GetAttribute("href");
                    replaceMethod(href, out newUrl);
                    element.SetAttribute("href", newUrl);
                }
            }

            if (images != null)
            {
                foreach (XmlElement element in images)
                {
                    href = element.GetAttribute("src");
                    replaceMethod(href, out newUrl);
                    element.SetAttribute("src", newUrl);
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// Replace the links searching for any anchor (a) or image (img) element.
        /// The delegate (callback method) passed is used to generate the new link based on the previous value.
        /// </summary>
        public void ReplaceLinks(ReplaceLinkHandler replaceMethod)
        {
            System.Xml.XmlNodeList anchors = mDoc.SelectNodes("//a");
            System.Xml.XmlNodeList images = mDoc.SelectNodes("//img");

            foreach (System.Xml.XmlElement element in anchors)
            {
                string href = element.GetAttribute("href");

                string newUrl;
                replaceMethod(href, out newUrl);
                element.SetAttribute("href", newUrl);
            }

            foreach (System.Xml.XmlElement element in images)
            {
                string href = element.GetAttribute("src");

                string newUrl;
                replaceMethod(href, out newUrl);
                element.SetAttribute("src", newUrl);
            }
        }