Click to See Complete Forum and Search --> : Navigating DOM in C Sharp
legend986
November 4th, 2008, 08:14 PM
Hi,
I am trying to navigate the DOM in C Sharp. I could do something like this in Javascript:
var subjectHeading = window.content.document.getElementById('canvas_frame').contentDocument.getElementsByTagName('h1');
But if I have to do the same in C Sharp on a HTML Document could someone please tell me how to proceed?
Arjay
November 4th, 2008, 09:28 PM
Look at the methods available in the XmlDocument (http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.aspx) class in Msdn.
legend986
November 4th, 2008, 09:57 PM
Thank You for your response. I would like to explain what I am doing further. When a page loads, I am trying to add an event listener (some advice on this is appreciated too) to a submit button on the page. The submit button is inside an iframe because of which in javascript I am first getting the canvas_frame and then getting the required element. So, I was wondering if the link that you pointed out (for XML DOM tree navigation) is the right way for my task.
Thread1
November 4th, 2008, 10:33 PM
you may try:
HtmlElementCollection = webBrowser1.Document.Window.Frames["frame id"].Document.GetElementsByTagName("h1");
legend986
November 5th, 2008, 02:04 PM
Thank You for the suggestion. Actually, I am not seeing the methods available in the first place:
WebBrowser webBrowser;
HTMLDocument document;
document = (HTMLDocument)webBrowser.Document;
And then should I just say document.Window.Frames... ? Because it is complaining that it is not a valid statement. Any suggestions on this please?
Thread1
November 7th, 2008, 05:14 AM
just tried it in vs 2005 and it is working fine, i can see it in the intelisense. what version you got there?
legend986
November 10th, 2008, 02:52 PM
Thank You. I am using VS2008. I am trying to create a BHO that can access the DOM of a website and then add some event listeners to it. Here's what I am trying (the code is in the BHO:IObjectWithSite method:
namespace BHO_IE
{
[
ComVisible(true),
Guid("8a194578-81ea-4850-9911-13ba2d71efbd"),
ClassInterface(ClassInterfaceType.None)
]
public class BHO:IObjectWithSite
{
WebBrowser webBrowser;
HTMLDocument document;
public void OnDocumentComplete(object pDisp, ref object URL)
{
document = (HTMLDocument)webBrowser.Document;
tagH1 = document.Window.Frames['canvas_frame'].Document.getElementsByTagName('h1');
}
// BHO Internal Functions
public static string BHOKEYNAME = "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Browser Helper Objects";
[ComRegisterFunction]
public static void RegisterBHO(Type type)
{
//Removed for code clarity
}
[ComUnregisterFunction]
public static void UnregisterBHO(Type type)
{
//Removed for code clarity
}
public int SetSite(object site)
{
//Removed for code clarity
}
public int GetSite(ref Guid guid, out IntPtr ppvSite)
{
//Removed for code clarity
}
}
}
Any suggestions please?
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.