0
<img src="images/img2.jpg"   alt="Cinderella" title="" />

I am getting image -> "src" value & getting the image & converting to Base64 string. Apart from this I want to replace value of src(images/img2.jpg) with base64 string value. But I am unable find the possible way.

Here is my total code(getting image "src" value & converting to string)

        XmlNodeList names = doc.GetElementsByTagName("img");
        for (uint j = 0; j < names.Length; j++)
        {
            XmlElement ele = (XmlElement)names.Item(j);
            var attri = ele.Attributes;
            var attrilist = attri.ToArray();
            //XmlElement name = names.ElementAt("src");
            for (int i = 0; i < attrilist.Length; i++)
            {

                if (attrilist[i].NodeName == "src")
                {
                    foreach (var itme in attrilist)
                    {
                        var srcval = attrilist.ToArray();
                        foreach (var srcvl in srcval)
                        {
                            var split = srcvl.NodeValue.ToString().Split('/');
                            StorageFile file = await appfolder.GetFileAsync(split.Last());
                           //converting image
                         }
                      }

I am unable to fetch the place of the "src" location in html file

Any help required.

Kumar
  • 864
  • 1
  • 22
  • 46
  • Maybe this? http://stackoverflow.com/questions/16664532/how-to-get-img-tags-source-from-given-html-string-using-c-sharp – I4V May 30 '13 at 07:54

1 Answers1

0

You shouldn't use Xml api to parse html document, try third part library like Html Agility Pack http://htmlagilitypack.codeplex.com

HtmlDocument doc = HtmlDocument.Parse(htmlString);
doc.DocumentNode.SelectSingleNode("//img").Attributes["src"].Value;

and that's all ! you can replace "//img" by an XPATH !

Julien
  • 51
  • 2