Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > .NET 3.5 and Visual Studio. 2008 > .NET Framework 3.5
|
.NET Framework 3.5 For discussion of the Microsoft .NET Framework 3.5.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the .NET Framework 3.5 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 15th, 2008, 04:32 AM
Registered User
 
Join Date: Sep 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to find no.of childnodes of a tag element?

I want to retrieve the web page content using Browser Helper object.
I had created BHO in C# with the help of http://www.codeproject.com/KB/cs/Att...O_with_C_.aspx

From this BHO, I want to retrieve the webpage content.



My code is:




BHO.cs



using System;
using System.Collections.Generic;
using System.Text;
using SHDocVw;
using mshtml;
using System.IO;
using Microsoft.Win32;
using System.Runtime.InteropServices;

namespace BHO_HelloWorld
{

    [
    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;

            HTMLDocument htmlDoc = new HTMLDocument();
            IHTMLDocument2 iHtmlDoc2 = null;
            iHtmlDoc2 = (IHTMLDocument2)htmlDoc;
            foreach (IHTMLElement htmlElem in (IHTMLElementCollection)document.documentElement.a ll)
            {
                if (htmlElem is HTMLFontElementClass)
                {
                    HTMLFontElementClass font = htmlElem as HTMLFontElementClass;


                    if (font.canHaveChildren)
                    {

                        var children = font.childNodes;

                        var child_length = children.__________;
                        System.Windows.Forms.MessageBox.Show("No.of ChildNodes:" + child_length);
                    }



                }
            }



        }





        #region BHO Internal Functions
        public static string BHOKEYNAME = "Software\\Microsoft\\Windows\\CurrentVersion\\Exp lorer\\Browser Helper Objects";

        [ComRegisterFunction]
        public static void RegisterBHO(Type type)
        {
            RegistryKey registryKey = Registry.LocalMachine.OpenSubKey(BHOKEYNAME, true);

            if (registryKey == null)
                registryKey = Registry.LocalMachine.CreateSubKey(BHOKEYNAME);

            string guid = type.GUID.ToString("B");
            RegistryKey ourKey = registryKey.OpenSubKey(guid);

            if (ourKey == null)
                ourKey = registryKey.CreateSubKey(guid);

            ourKey.SetValue("Alright", 1);
            registryKey.Close();
            ourKey.Close();
        }

        [ComUnregisterFunction]
        public static void UnregisterBHO(Type type)
        {
            RegistryKey registryKey = Registry.LocalMachine.OpenSubKey(BHOKEYNAME, true);
            string guid = type.GUID.ToString("B");

            if (registryKey != null)
                registryKey.DeleteSubKey(guid, false);
        }

        public int SetSite(object site)
        {

            if (site != null)
            {
                webBrowser = (WebBrowser)site;
                webBrowser.DocumentComplete += new DWebBrowserEvents2_DocumentCompleteEventHandler(th is.OnDocumentComplete);

            }
            else
            {
                webBrowser.DocumentComplete -= new DWebBrowserEvents2_DocumentCompleteEventHandler(th is.OnDocumentComplete);
                webBrowser = null;
            }

            return 0;

        }

        public int GetSite(ref Guid guid, out IntPtr ppvSite)
        {
            IntPtr punk = Marshal.GetIUnknownForObject(webBrowser);
            int hr = Marshal.QueryInterface(punk, ref guid, out ppvSite);
            Marshal.Release(punk);

            return hr;
        }





        #endregion


    }
}








IobjectWithSite.cs:




using System;
using System.Collections.Generic;
using System.Text;

using System.Runtime.InteropServices;

namespace NewPage
    {


    [
    ComVisible(true),
    InterfaceType(ComInterfaceType.InterfaceIsIUnknown ),
    Guid("FC4801A3-2BA9-11CF-A229-00AA003D7352")
    ]

    public interface IObjectWithSite
    {
        [PreserveSig]
        int SetSite([MarshalAs(UnmanagedType.IUnknown)]object site);
        [PreserveSig]
        int GetSite(ref Guid guid, out IntPtr ppvSite);
    }

}



Using this, how can i get no.of childnodes of a tag element







Similar Threads
Thread Thread Starter Forum Replies Last Post
Cannot find sub element riffla XSLT 2 March 17th, 2008 08:47 AM
VBA to find Device Instance Number and tag sswcharlie Excel VBA 0 May 29th, 2007 04:21 PM
Conditional Output on childnodes? fahmyr XSLT 3 September 11th, 2006 11:49 AM
How to use xsl:element tag??? NewToXSL XSLT 2 June 8th, 2006 05:54 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.