473,670 Members | 2,499 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 14505
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.Docu mentCompleted event. It
should look like the following:

private void webBrowser1_Doc umentCompleted( object sender,
WebBrowserDocum entCompletedEve ntArgs 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
FillTreeViewRec ursively(rootNo de, webBrowser1.Doc ument.All);
}

6. Create the FillTreeViewRec ursively method:

private void FillTreeViewRec ursively(TreeNo de currentNode,
HtmlElementColl ection 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.Nod es.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
FillTreeViewRec ursively(node, element.All);
}
}
--------
But, the program run for a long time, i think the FillTreeViewRec ursively
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
3882
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 data strucure like this: structList =
18
3746
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 mung most of it using several regular expressions, but I've become stuck at this point. I can't figure out how to grab only the <tr> tags that are associated with tables that are two levels deep. I feel like I got close, but it seems that...
16
2879
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 loaded into cache, the slideshow doesn't look very nice. I am not sure how/when to call the slideshow() function to make sure it starts after the preload has been completed.
4
1487
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
1541
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 elements that I want to convert to html as nested definition and unordered lists in the following way. <object> <name>ball</ball> <desc>
2
1485
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 in a JSR168-Portlet and in a Python-Environment as well, so I want them to be parsed by an xslt to html which then could be shown in a web browser.
53
4113
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 javascript object and that's all. No need to know CSS hacks, no need to clutter your html with tables. http://www.bravelayout.scarabeo.biz/Quickstart
7
5589
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 found a way to do it in Python.
11
4556
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 (e.g. <br>). Seems simple enough, but I'm having some trouble with it. regexps trip up because I also have to take into account 'img', 'meta', 'link' tags, not just the simple 'br' and 'hr' tags. Well, maybe there's a simple way to do that...
4
2031
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 is valid. The sorts of things that cause problems are unmatched quotes inside the HTML and mismatched <>'s around the HTML. There are probably others (thus demonstrating why I need to avoid parsing it). The mismatched <>'s are not too...
0
8466
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8384
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8901
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8813
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8591
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8659
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4208
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4388
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2799
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.