This project has moved and is read-only. For the latest updates, please go here.

not getting correct value from img src tag

Oct 29, 2011 at 12:40 PM

i have this code:

                HtmlAgilityPack.HtmlWeb loader = new HtmlAgilityPack.HtmlWeb();
                var doc = loader.Load("");

                //firstly, find the div node which its id is locutor
                var divNode = doc.DocumentNode.SelectSingleNode("//div[@id='locutor']");
                //secondly, find the img node in the divNode
                var srcNode = divNode.SelectSingleNode("//img[@src]");
                //the last, retrieve the value of the src property in the img node
                string src = srcNode.GetAttributeValue("src", "none value");
the problem is  the var divnode in inner html is reading correctly all div tags and when going to get the img src tag is returning and empty string if someone can clarefy me i think is a bug or the htmlaggility pack 
how ever a workarround is that: 
   string pageUrl = "";

                HtmlAgilityPack.HtmlWeb hDoc = new HtmlAgilityPack.HtmlWeb();
                var doc = hDoc.Load(pageUrl);

                var divNode = doc.DocumentNode.SelectSingleNode("//div[@id='locutor']");
                string src1 = divNode.InnerHtml;
                int startIndex = src1.IndexOf('h');
                int endIndex = src1.IndexOf("png") + 3;
                string strSrc = src1.Substring(startIndex, (src1.Length - startIndex) - (src1.Length - endIndex));
butwhy the frist code is givving empty string