473,513 Members | 2,505 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

HTML DOM Tree

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
4 14498
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3865
by: Gregor Horvath | last post by:
Hi, Before I reinvent the wheel I`d like to ask if someone has done this before since I did not find an advice at Google. The goal is to create a dynamic Tree View in HTML. Say I have a...
18
3734
by: Shannon Jacobs | last post by:
Trying to solve this with a regex approach rather than the programmatic approach of counting up and down the levels. I have a fairly complicated HTML page that I want to simplify. I've been able to...
16
2856
by: Terry | last post by:
Hi, This is a newbie's question. I want to preload 4 images and only when all 4 images has been loaded into browser's cache, I want to start a slideshow() function. If images are not completed...
4
1473
by: mikelinyoho | last post by:
regards: Could HTML be characterized by a DOM tree? Could XHTML be characterized by a DOM tree? thank you best wishes
4
1527
by: Ron Adam | last post by:
I'm new to element tree and haven't been able to find a simple solution to this problem yet. So maybe someone can point me in the right direction. I have an element tree structure of nested...
2
1480
by: sebastian.langer | last post by:
Hi! Certainly somebody had my problem before and could give me just some hints, how to solve it: I have an xml file, which contains scientific data in a tree form. The data should be changed...
53
4064
by: brave1979 | last post by:
Please check out my javascript library that allows you to create any layout for your web page, nested as deep as you like, adjusting to width and height of a browser window. You just describe it in...
7
5584
by: Benjamin | last post by:
I'm trying to parse an HTML file. I want to retrieve all of the text inside a certain tag that I find with XPath. The DOM seems to make this available with the innerHTML element, but I haven't...
11
4512
by: Tim Arnold | last post by:
hi, I've got lots of xhtml pages that need to be fed to MS HTML Workshop to create CHM files. That application really hates xhtml, so I need to convert self-ending tags (e.g. <br />) to plain html...
4
2025
by: Steve Swift | last post by:
I have a page that accepts user input, including HTML. I would like to offer a preview of what the users HTML will look like, but I'd also like to avoid having to parse their HTML to ensure that it...
0
7260
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7384
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7539
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7101
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7525
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5089
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4746
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3234
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
802
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.