0
comments
Posted by
Belbinson Toby ,
3:31 AM
This is an agile HTML parser that builds a read/write DOM and supports plain XPATH or XSLT (you actually don't HAVE to understand XPATH nor XSLT to use it, don't worry...). It is a .NET code library that allows you to parse "out of the web" HTML files. The parser is very tolerant with "real world" malformed HTML. The object model is very similar to what proposes System.Xml, but for HTML documents (or streams).
Html Agility Pack now supports Linq to Objects (via a LINQ to Xml Like interface). Check out the new beta to play with this feature
Sample applications:
- Page fixing or generation. You can fix a page the way you want, modify the DOM, add nodes, copy nodes, well... you name it.
- Web scanners. You can easily get to img/src or a/hrefs with a bunch XPATH queries.
- Web scrapers. You can easily scrap any existing web page into an RSS feed for example, with just an XSLT file serving as the binding. An example of this is provided.
There is no dependency on anything else than .Net's XPATH implementation. There is no dependency on Internet Explorer's MSHTML dll or W3C's HTML tidy or ActiveX / COM object, or anything like that. There is also no adherence to XHTML or XML, although you can actually produce XML using the tool. The version posted here on CodePlex is for the .NET Framework 2.0. If you need the old version, please go to the old page or drop me a note.
Posted by
Belbinson Toby ,
Saturday, March 28, 2015
7:39 AM
A critical aspect of COM is how clients and servers interact. A COM client is whatever code or object gets a pointer to a COM server and uses its services by calling the methods of its interfaces. A COM server is any object that provides services to clients; these services are in the form of COM interface implementations that can be called by any client that is able to get a pointer to one of the interfaces on the server object.
There are two main types of servers, in-process and out-of-process. In-process servers are implemented in a dynamic linked library (DLL), and out-of-process servers are implemented in an executable file (EXE). Out-of-process servers can reside either on the local computer or on a remote computer. In addition, COM provides a mechanism that allows an in-process server (a DLL) to run in a surrogate EXE process to gain the advantage of being able to run the process on a remote computer. For more information, see DLL Surrogates.
The COM programming model and constructs have now been extended so that COM clients and servers can work together across the network, not just within a given computer. This enables existing applications to interact with new applications and with each other across networks with proper administration, and new applications can be written to take advantage of networking features.
COM client applications do not need to be aware of how server objects are packaged, whether they are packaged as in-process objects (in DLLs) or as local or remote objects (in EXEs). Distributed COM further allows objects to be packaged as service applications, synchronizing COM with the rich administrative and system-integration capabilities of Windows.
Note Throughout this documentation the acronym COM is used in preference to DCOM. This is because DCOM is not separate;it is just COM with a longer wire. In cases where what is being described is specifically a remote operation, the term distributed COM is used.
COM is designed to make it possible to add the support for location transparency that extends across a network. It allows applications written for single computers to run across a network and provides features that extend these capabilities and add to the security necessary in a network. (For more information, see Security in COM.)
COM specifies a mechanism by which the class code can be used by many different applications.
For more information, see the following topics:
- Getting a Pointer to an Object
- Creating an Object Through a Class Object
- COM Server Responsibilities
- Persistent Object State
- Providing Class Information
- Inter-Object Communication
Related topics
Posted by
Belbinson Toby ,
Wednesday, March 4, 2015
4:47 AM
Introduction
Type casting is one of the unavoidable things in software development. In many situations we need to convert one object (Type) to another object (Type) and some times we get an exception like this: "Cannot implicitly convert type 'Object one' to 'object two'". To avoid this type of exceptions and check object compatibility, C# provides two operators namely
is and as.
is operator
The
is operator in C# is used to check the object type and it returns a bool value: true if the object is the same type and false if not.
For
null objects, it returns false.
Syntax:
Hide Copy Code
bool isobject = (Object is Type);
Example:
Hide Shrink
Copy Code
namespace IsAndAsOperators
{
// Sample Student Class
class Student
{
public int stuNo { get; set; }
public string Name { get; set; }
public int Age { get; set; }
}
// Sample Employee Class
class Employee
{
public int EmpNo { get; set; }
public string Name { get; set; }
public int Age { get; set; }
public double Salary { get; set; }
}
class Program
{
static void Main(string[] args)
{
Student stuObj = new Student();
stuObj.stuNo = 1;
stuObj.Name = "Siva";
stuObj.Age = 15;
Employee EMPobj=new Employee();
EMPobj.EmpNo=20;
EMPobj.Name="Rajesh";
EMPobj.Salary=100000;
EMPobj.Age=25;
// Is operator
// Check Employee EMPobj is Student Type
bool isStudent = (EMPobj is Student);
System.Console.WriteLine("Empobj is a Student ?: {0}", isStudent.ToString());
// Check Student stiObj is Student Typoe
isStudent = (stuObj is Student);
System.Console.WriteLine("Stuobj is a Student ?: {0}", isStudent.ToString());
stuObj = null;
// Check null object Type
isStudent = (stuObj is Student);
System.Console.WriteLine("Stuobj(null) is a Student ?: {0}", isStudent.ToString());
System.Console.ReadLine();
}
}
Output
Hide Copy Code
Empobj is a Student ?: False
Stuobj is a Student ?: True
Stuobj(null) is a Student ?: False
as operator
The
as operator does the same job of is operator but the difference is instead of bool, it returns the object if they are compatible to that type, else it returns null.
Syntax:
Hide Copy Code
Type obj = Object as Type;
Example:
Hide Shrink
Copy Code
namespace IsAndAsOperators
{
// Sample Student Class
class Student
{
public int stuNo { get; set; }
public string Name { get; set; }
public int Age { get; set; }
}
// Sample Employee Class
class Employee
{
public int EmpNo { get; set; }
public string Name { get; set; }
public int Age { get; set; }
public double Salary { get; set; }
}
class Program
{
static void Main(string[] args)
{
Student stuObj = new Student();
stuObj.stuNo = 1;
stuObj.Name = "Praveen";
stuObj.Age = 15;
Employee EMPobj=new Employee();
EMPobj.EmpNo=20;
EMPobj.Name="Rajesh";
EMPobj.Salary=100000;
EMPobj.Age=25;
System.Console.WriteLine("Empobj is a Student ?: {0}", CheckAndConvertobject(EMPobj));
System.Console.WriteLine("StuObj is a Student ?: {0}", CheckAndConvertobject(stuObj));
System.Console.ReadLine();
}
public static string CheckAndConvertobject(dynamic obj)
{
// If obj is Type student it asign value to Stuobj else it asign null
Student stuobj = obj as Student;
if (stuobj != null)
return "This is a Student and his name is " + stuobj.Name;
return "Not a Student";
}
}
}
Output:
Hide Copy Code
Empobj is a Student ?: Not a Student
StuObj is a Student ?: This is a Student and his name is Praveen
Advantage of 'as' over 'is
In the case of
is operator, to type cast, we need to do two steps:- Check the Type using
is - If it’s
truethen Type cast
Actually this affects the performance since each and every time the CLR will walk the inheritance hierarchy, checking each base type against the specified type. To avoid this, use
as it will do it in one step. Only for checking the type should we use the is operator.
Subscribe to:
Posts (Atom)



