|
Welcome,
Guest
|
Enhancing The Web Browser Control For XML
(1 viewing) (1) Guest
A programming language that evolved in part from Microsoft C++, C# was designed for building enterprise-level applications that run on the .NET Framework. C# is simple, modern, type safe, and object oriented. Whether you’re new to the language or an old pro, you’ll find articles in this section that will help you get your projects done.
|
TOPIC: Enhancing The Web Browser Control For XML
Enhancing The Web Browser Control For XML 10 Apr 2010 01:36 #336
|
Introduction
I've read and heard comments lamenting the fact that the MS .net Web Browser control (System.Windows.Forms.WebBrowser) doesn't behave like Internet Explorer, or lacks some of the feature support that IE has. Chief among these complaints is the one that it doesn't support the displaying of XML the way IE does, all pretty and ready for printing. You could take the view, as do I, that this is the way it should be. The Web Browser control is a basic (although powerful) managed wrapper for the Web Browser ActiveX control (in Shdocvw.dll). IE uses Shdocvw.dll too, but when you use a .net Web Browser control in your application, you're not using a component of IE, you're using a component that IE uses. IE extends it's functionality, and if the need arises... so must you. So Very Useful Since the basic WB control can be so useful in many different applications that you develop, I recommend you consider creating a wrapper of your own which you reuse in each project where you need a WB control. As you progress from project to project, you'll add more features as needed by each project. Each time you do this, you potentially save yourself a lot of time with each new project you use it in. You can either put it into its own class library project, as I have in this article. Alternatively you could maintain one code file which you keep importing into other projects. The latter approach requires you to be using a version control or file repository system (such as SourceSafe) so that you can have the same physical file in many projects. Besides that, you may have other class files that you want to add later. So I would suggest building your own library to contain it. No Need - There's One Right Here So that's the approach I've taken with the project files associated with this article. I've created a Class Library that contains one class which, using my extensive imagination and creative flare I have named... 'WebBrowser'. This is of course a wrapper for... you guessed... the WebBrowser. For those new to the subject of inheritance, the distinction between the two rests in the fact that EnhancedControls.WebBrowser (my namespace) inherits from, and extends System.Windows.Forms.WebBrowser (an MS namespace). So the issue my WB control will tackle is the one I mentioned at the start - support for displaying XML. But you can add other features to it that are appropriate for your needs too. Transforming XML Some people are prone to turning this subject into rocket science. My view is that if a transformation works with the XML files you're working with... it works. Compile the code, make the coffee, and move on. You can always add support for other transformations later on when you encounter some XML with which it doesn't work, if that ever happens. So when I went out looking for a good transformation I found one provided by Steve Muench. I embedded that xslt file into the resources of my library project because I don't want my library to have any dependencies on files external to itself. Once you have an appropriate transformation at hand, actually making the transform happen is very easy. Here is the code for that: /// <summary>One of my big problems is that I don't always practice what I preach. Only two paragraphs and one sub-routine ago did I say (in not so many words), don't bother to cross bridges you haven't come to yet. Some bridges I immediately spotted in the foggy distance convinced me that I may not always have an XmlReader object to pass to the DisplayPrettyXML() routine. Sometimes I'll have a file, other times perhaps and XMLDocument object. So I immediately crossed all the bridges not yet reached, and wrote four overloads for DisplayPrettyXML(). I'll list just one of them here: /// <summary>Using the code To test my new WB component I created a Windows Forms Application, with one form, dropped my WB control onto that form and added five buttons. Each button causes the WB control to do the same thing, but with five different (although they share the same structure) XML files. #region cmdFile_ClickPoints of Interest
This attachment is hidden for guests. Please log in or register to see it. This attachment is hidden for guests. Please log in or register to see it.
Attachments:
|
|
|
The following user(s) said Thank You: fredyvasquez@hotmail.com
|
|
Moderators: mnjon
Time to create page: 0.48 seconds







