public virtual string PublishBinariesInRichTextField(string xhtml)
        {

            // rich text field is well-formed, except that it does not always have a root element
            // to be sure it can be parsed, we will add a root and remove it afterwards

            TridionXml xml = new TridionXml();
            xml.LoadXml("<tmproot>" + xhtml + "</tmproot>");

            foreach (XmlElement img in xml.SelectNodes("//xhtml:img[@xlink:href[starts-with(string(.),'tcm:')]]", xml.NamespaceManager))
            {
                log.Debug("found img node " + img.OuterXml);
                XmlAttribute link = (XmlAttribute)img.SelectSingleNode("@xlink:href", xml.NamespaceManager);
                log.Debug("about to publish binary with uri " + link.Value);
                string path = PublishMultimediaComponent(link.Value);
                log.Debug("binary will be published to path " + path);
                img.SetAttribute("src", path);

            }


            foreach (XmlElement img in xml.SelectNodes("//xhtml:a[@xlink:href[starts-with(string(.),'tcm:')]]", xml.NamespaceManager))
            {
                log.Debug("found link node " + img.OuterXml);
                XmlAttribute link = (XmlAttribute)img.SelectSingleNode("@xlink:href", xml.NamespaceManager);
                Component component = (Component)engine.GetObject(link.Value);
                if (component.ComponentType == ComponentType.Multimedia)
                {
                    log.Debug("about to publish binary with uri " + link.Value);
                    string path = PublishMultimediaComponent(link.Value);
                    log.Debug("binary will be published to path " + path);
                    img.SetAttribute("src", path);
                }
                else
                {
                    log.Debug("Component is not a multimedia component.");
                }

            }
            return xml.DocumentElement.InnerXml;
        }
        public virtual string PublishBinariesInRichTextField(string xhtml, BuildProperties buildProperties)
        {

            // rich text field is well-formed, except that it does not always have a root element
            // to be sure it can be parsed, we will add a root and remove it afterwards

            TridionXml xml = new TridionXml();
            xml.LoadXml("<tmproot>" + xhtml + "</tmproot>");

            foreach (XmlElement elmt in xml.SelectNodes("//*[@xlink:href[starts-with(string(.),'tcm:')]]", xml.NamespaceManager))
            {
                log.Debug("found node " + elmt.OuterXml);
                XmlAttribute link = (XmlAttribute)elmt.SelectSingleNode("@xlink:href", xml.NamespaceManager);

                string uri = link.Value;
                Component c = (Component) engine.GetObject(uri);
                if (c.ComponentType != ComponentType.Multimedia)
                {
                    continue;
                }
                log.Debug("about to publish binary with uri " + link.Value);
                string path = PublishMultimediaComponent(link.Value, buildProperties);
                log.Debug("binary will be published to path " + path);

                if (elmt.LocalName.ToLower() == "img")
                {
                    elmt.SetAttribute("src", path);
                }
                else
                {
                    elmt.SetAttribute("href", path);
                }
                elmt.RemoveAttributeNode(link);
            } 
            return xml.DocumentElement.InnerXml;
        }