1
<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.

1

1 Answer 1

1

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 !

Sign up to request clarification or add additional context in comments.

1 Comment

@Jullien Can you tell me how to make it using XmlDocument. Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.