Click here to Skip to main content
15,885,767 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a requirement of getting child tag content..here is requirement

HTML
<div>
<p>78.90KB
<a rel="nofollow" href="https://developers.google.com/speed/articles/web-metrics" target="_blank">average is 320 Kb</a>
</p>
</div>

here i want to get only 78.90KB...but as per my code i am getting entire <p> tag with also <a> tag...actually i don't need <a> tag
here is my c# code....first i am getting <div> tags of html and i am looping the <div> tag for searching the <p> tag....

XML
List<string> pagesize = new List<string>();

           string _pattern = @"\s*(.+?)\s*"
  string _pattern1=@"\s*(.+?)\s*";
 string _headPattern = string.Format("<div class=\"part text \">{0}</div>", _pattern);
         string _childpattern=string.Format("<p itemprop=\"fileSize\">{0}</p>",_pattern1);

         Match _match = Regex.Match(data, _headPattern, RegexOptions.Multiline);
         MatchCollection _match1 = Regex.Matches(data,_headPattern,RegexOptions.Multiline);
 foreach (Match tElement in _match1)
            {
                string element = tElement.Groups[1].Value;
              
                if (element==_childpattern)
                {
                    element = element.Replace("<p>", string.Empty);
                    element = element.Replace("</p>",string.Empty);
                    pagesize.Add(element);
                  
                }
                    
               
            }

          return PageSize = pagesize[0];       
       }

is there any way to get only the element which i need.....please any suggestions or advices.......:)
Posted
Updated 22-Jul-14 20:54pm
v2
Comments
Kornfeld Eliyahu Peter 23-Jul-14 2:55am    
I think learning some JavaScript library (like JQuery) can make your work much easier...

1 solution

Use Jquery to do this:
XML
<script type="text/javascript">

        $(document).ready(function () {
            alert($('div p').first().contents().eq(0).text());
        });
    </script>

Regards..
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900