By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,050 Members | 1,564 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,050 IT Pros & Developers. It's quick & easy.

HTML DOM Tree

P: n/a
I want to construct a DOM tree from the HTML source code. How can i get it ?
Do you show me some source code for this.
Thanks.
Sep 29 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
See HtmlDocument Class in MSDN

--
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche


"Le Minh" wrote:
I want to construct a DOM tree from the HTML source code. How can i get it ?
Do you show me some source code for this.
Thanks.
Sep 29 '06 #2

P: n/a
I had tried to use it. Create HtmlDocument from Uri and extract node from
it. But there smth wrong. The result it not good.
Sep 29 '06 #3

P: n/a
Hello Le,

And? what's wrong there are no one clairvoyant

LMI had tried to use it. Create HtmlDocument from Uri and extract node
LMfrom it. But there smth wrong. The result it not good.
LM>
---
WBR,
Michael Nemtsev :: blog: http://spaces.live.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
Sep 29 '06 #4

P: n/a
I follow a suggest by Dave Sexton:
1. Create a new Windows application project.
2. Add a WebBrowser control from the toolbox onto Form1. (You can position
it however you'd like)
3. Add a TreeView control from the toolbox onto Form1. (You can position it
however you'd like)
4. Set the WebBrowser.Url property to the url of your html document (this is
the easiest way to load the document).
5. Create an event handler for the WebBrowser.DocumentCompleted event. It
should look like the following:

private void webBrowser1_DocumentCompleted(object sender,
WebBrowserDocumentCompletedEventArgs e)
{
// make sure that the TreeView is cleared in case the browser navigates
to another url
treeView1.Nodes.Clear();

// create the root node for the TreeView, which will contain all other
nodes
TreeNode rootNode = treeView1.Nodes.Add("Root");

// Fill the TreeView, recursively, starting from the root node
FillTreeViewRecursively(rootNode, webBrowser1.Document.All);
}

6. Create the FillTreeViewRecursively method:

private void FillTreeViewRecursively(TreeNode currentNode,
HtmlElementCollection elements)
{
// loop through the specified collection of elements and create their
respective nodes
foreach (HtmlElement element in elements)
{
// create a new node for the current element and add it under the
currentNode
TreeNode node = currentNode.Nodes.Add(element.TagName);

// optional: store a reference to the element that this node
represents
node.Tag = element;

// create the nodes under this node for the elements contained by
the current element
FillTreeViewRecursively(node, element.All);
}
}
--------
But, the program run for a long time, i think the FillTreeViewRecursively
method is raise a infinite loop
Sep 29 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.