In the application i want to show only one specific part of the webpage that is inside an element.
<div id="content">
I only want to show that's inside the above HTML element. How can i achieve this with web browser control in windows phone 8?
If you can't filter the web page directly on the web server.
You can either inject some javascript code to filter DOM after loading the full web page into web browser control or parse the HTML before injecting the filtered content into the web browser control with NavigateToString
method as indicated by Fisher YoYo
.
Since HTML parsing is quite challenging, you should use this party for this task: Html Agility Pack.
Here is an example based on your question:
static void Main(string[] args)
{
HtmlAgilityPack.HtmlWeb web = new HtmlWeb();
HtmlDocument document = web.Load("http://localhost/testAgilityPack.html");
HtmlNode contentNode = document.DocumentNode.SelectSingleNode("//div[@id='content']");
Console.WriteLine(contentNode.WriteTo());
Console.ReadLine();
}
This snippet will extract the div
HTML element with attribute id
equals to content
and export it into a string.