Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
Hi All,
 
Looking to create a DOM in HTML from aload of HTML.
 
I currently have a program that is capable of getting the HTML from a website and dumping it into a textbox. from this i was to create a DOM.
 
Anyone have any ideas... this looks perfect....
 
HTML DOM Using .NET[^]
 
However, its C# and won't work in VB.
 
Thanks.
Posted 22-Feb-13 4:32am
Comments
ThePhantomUpvoter at 22-Feb-13 9:42am
   
So compile the C# code to a DLL and use it from your VB code.
Chris Reynolds (UK) at 22-Feb-13 9:46am
   
It should be fairly straightforward to convert the C# into VB, the .NET framework is the same for both so just take it a line or two at a time and you should be OK
ryanb31 at 22-Feb-13 9:48am
   
C# and VB.Net are so close that going between generally is not that hard. However, you can try this tool http://www.carlosag.net/tools/codetranslator/
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

If you use the WebBrowser Class[^], then you can get the DOM direct from the Document property, which is an instance of the HtmlDocument Class[^].
  Permalink  
Comments
Member 9829514 at 22-Feb-13 10:23am
   
Would you have some sample code please?
Richard MacCutchan at 22-Feb-13 10:41am
   
See my other solution below.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

This code gets the HTML from a control that is inherited from WebBrowser, and uses the DOM to find particular tables and items within it.
// logout from 3Rings
HtmlElement element = Document.GetElementById("directory_list");
 
// get the table header collection (one element)
HtmlElementCollection trCollection = element.GetElementsByTagName("THEAD");
// get the header items collection
trCollection = trCollection[0].GetElementsByTagName("TH");
int xName = -1;
int xEmail = -1;
int nIndex = 0;
foreach (HtmlElement trItem in trCollection)
{
	Debug.WriteLine(trItem.InnerText);
	string strHeading = trItem.InnerText.Trim().ToLower();
	if (strHeading.Equals("name"))
		xName = nIndex;
	if (strHeading.Equals("email"))
		xEmail = nIndex;
	nIndex++;
}
The documentation will offer further examples, or you could search the CodeProject articles for more samples.
  Permalink  

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

  Print Answers RSS
0 CPallini 235
1 DamithSL 225
2 OriginalGriff 198
3 George Jonsson 170
4 Maciej Los 165
0 OriginalGriff 5,305
1 DamithSL 4,382
2 Maciej Los 3,760
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,901


Advertise | Privacy | Mobile
Web01 | 2.8.141216.1 | Last Updated 22 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100