Translate

Thursday, December 13, 2012

Convert word file to pdf in c#


//Change the path of the .docx file and filename to your file name.
        object paramSourceDocPath = Server.MapPath("IITJEEPaper-1Final.docx");
        object paramMissing = Type.Missing;

        ApplicationClass wordApplication = new ApplicationClass();
        Document wordDocument = null;

        //Change the path of the .pdf file and filename to your file name.
        string paramExportFilePath = Server.MapPath("IITJEEPaper-1Final.pdf");
        WdExportFormat paramExportFormat = WdExportFormat.wdExportFormatPDF;
        bool paramOpenAfterExport = false;
        WdExportOptimizeFor paramExportOptimizeFor =
            WdExportOptimizeFor.wdExportOptimizeForPrint;
        WdExportRange paramExportRange = WdExportRange.wdExportAllDocument;
        int paramStartPage = 0;
        int paramEndPage = 0;
        WdExportItem paramExportItem = WdExportItem.wdExportDocumentContent;
        bool paramIncludeDocProps = true;
        bool paramKeepIRM = true;
        WdExportCreateBookmarks paramCreateBookmarks =
            WdExportCreateBookmarks.wdExportCreateWordBookmarks;
        bool paramDocStructureTags = true;
        bool paramBitmapMissingFonts = true;
        bool paramUseISO19005_1 = false;

        try
        {
            // Open the source document.
            wordDocument = wordApplication.Documents.Open(
                ref paramSourceDocPath, ref paramMissing, ref paramMissing,
                ref paramMissing, ref paramMissing, ref paramMissing,
                ref paramMissing, ref paramMissing, ref paramMissing,
                ref paramMissing, ref paramMissing, ref paramMissing,
                ref paramMissing, ref paramMissing, ref paramMissing,
                ref paramMissing);

            // Export it in the specified format.
            if (wordDocument != null)
                wordDocument.ExportAsFixedFormat(paramExportFilePath,
                    paramExportFormat, paramOpenAfterExport,
                    paramExportOptimizeFor, paramExportRange, paramStartPage,
                    paramEndPage, paramExportItem, paramIncludeDocProps,
                    paramKeepIRM, paramCreateBookmarks, paramDocStructureTags,
                    paramBitmapMissingFonts, paramUseISO19005_1,
                    ref paramMissing);
        }
        catch (Exception ex)
        {
            // Respond to the error
            //System.Windows.Forms.MessageBox.Show(ex.Message);
            Response.Write(ex.Message);
        }
        finally
        {
            // Close and release the Document object.
            if (wordDocument != null)
            {
                wordDocument.Close(ref paramMissing, ref paramMissing,
                    ref paramMissing);
                wordDocument = null;
            }

            // Quit Word and release the ApplicationClass object.
            if (wordApplication != null)
            {
                wordApplication.Quit(ref paramMissing, ref paramMissing,
                    ref paramMissing);
                wordApplication = null;
            }

            GC.Collect();
            GC.WaitForPendingFinalizers();
            GC.Collect();
            GC.WaitForPendingFinalizers();
        }
    }

Thursday, October 4, 2012

Sync data between multiple database

Option one is to enable binary logs on each laptop and then replay these on the master database when reconnected. You can use 

mysqlbinlog logfile > mysql --host=masterdbserver 

This should be straightforward. It will apply all changes from the offline laptops to the master. 

Option two is to sync only changed and inserted records from the laptops to the master with MySQL Table Sync (http://sourceforge.net/projects/mysqltoolkit). Use the --onlydo option for this. 

Then you have to get the changes back from the central database to the laptops. If you are using MyISAM tables, rsync might be the best option; otherwise you can use MySQL Table Sync again.

Friday, September 14, 2012

Multiple Interface Inheritance with same method name


public interface ITest 
{
    void Test();
}

public interface ITest2 

{
    void Test();
}

public class Dual : ITest, ITest2
{
    void ITest.Test() 
   {
        Console.WriteLine("ITest.Test");
    }
    void ITest2.Test() 
   {
        Console.WriteLine("ITest2.Test");
    }
}

var dual = new Dual();
ITest test = dual;
test.Test();
ITest2 test2 = dual;
test2.Test();

Thursday, September 6, 2012

Advantage and disadvantage of self hosting?


Advantages of Self-Hosting:
  • Is easy to use : With only a few lines of code you have your service running.
  • Is flexible : You can easily control the lifetime of your services through the Open() and Close() methods ofServiceHost.
  • Is easy to debug : Debugging WCF services that are hosted in a self-hosted environment provides a familiar way of debugging, without having to attach to separate applications that activate your service.
  • Is easy to deploy : In general, deploying simple Windows applications is as easy as xcopy. You don’t need any complex deployment scenarios on server farms, and the like, to deploy a simple Windows application that serves as a WCF ServiceHost.
  • Supports all bindings and transports : Self-hosting doesn’t limit you to out-of-the-box bindings and transports whatsoever. On Windows XP and Windows Server 2003, IIS limits you to HTTP only.

Disadvantages of Self-Hosting:
  • Limited availability : The service is reachable only when the application is running.
  • Limited features : Self-hosted applications have limited support for high availability, easy manageability, robustness, recoverability, versioning, and deployment scenarios. These scenarios have become a standard in last few years. Such features are provided by the WAS (Windows Activation Service) which is a part of IIS7 (delivered with Vista and Win2008). This hosting mechanism allows you to host the service by using of protocols like MSMQ, HTTP and TCP. 

What is charindex?

Sql charindex is a sql server function that indicates the first position of a character or a character string within another character string. When a character or character string is found with sql charindex, the starting position is indicated with a non-zero positive integer value. If a character or character string is not found with charindex, a zero integer value is returned. charindex's starting position is 1, unlike other index search functions that would normally return 0 as the first position. 


CHARINDEX ( expression1 ,expression2 [ , start_location ] ) 


expression1
Is an expression that contains the sequence of characters to be found. expression1 is an expression of the character string data type category.
expression2
Is an expression, typically a column searched for the specified sequence. expression2 is of the character string data type category.
start_location
Is the character position to start searching for expression1 in expression2. If start_location is not specified, is a negative number, or is zero, the search starts at the beginning of expression2start_location can be of type bigint.

Tuesday, September 4, 2012

What are Dead letter queues?

The main use of queue is that you do not need the client and the server running at one time. Therefore, it is possible that a message will lie in queue for long time until the server or client picks it up. But there are scenarios where a message is of no use after a certain time. Therefore, these kinds of messages if not delivered within that time span it should not be sent to the user.

What are Volatile queues?

There are scenarios in the project when you want the message to deliver in proper time. The timely delivery of message is more important than losing message. In these scenarios, Volatile queues are used.
 

What is SOAP?


SOAP, Simple Object Access Protocol is a communication protocol, a way to structure data before transmitting it, is based on XML standard. It is developed to allow communication between applications of different platforms and programming languages via internet.
It can use range of protocols such as HTTP, FTP, SMTP, Post office protocal 3(POP3) to carry documents.
Http-Get, Http-Post works with name/value pair which means transferring complex object is not possible with these protocols, whereas SOAP serializes complex structure, such as ASP.NET DataSets, complex arrays, custom types and XML nodes before transmitting and thus allows exchange of complex objects between applications.

What is static class and why we use it?

A class can be declared static, indicating that it contains only static members. It is not possible to create instances of a static class using the new keyword. Static classes are loaded automatically by the .NET Framework common language runtime (CLR) when the program or namespace containing the class is loaded.

Creating a static class is therefore much the same as creating a class that contains only static members and a private constructor. A private constructor prevents the class from being instantiated.

Advantage of static class

The advantage of using a static class is that the compiler can check to make sure that no instance members are accidentally added. The compiler will guarantee that instances of this class cannot be created.

Static classes are sealed and therefore cannot be inherited. Static classes cannot contain a constructor, although it is still possible to declare a static constructor to assign initial values or set up some static state.
Static class are used when a class provides functionality that is not specific to any unique instance. It provide the functionality a global access. 
Static methods do not consume any dynamic memory. Static class is load in stack memory and so the execution will be fast.

Friday, August 31, 2012

Easy Sequence of SELECT FROM JOIN WHERE GROUP BY HAVING ORDER BY

SELECT yourcolumns
FROM tablenames
JOIN tablenames
WHERE condition
GROUP BY yourcolumns
HAVING aggregatecolumn condition
ORDER BY yourcolumns

Easy Sequence of SELECT FROM JOIN WHERE GROUP BY HAVING ORDER BY

SELECT yourcolumns
FROM tablenames
JOIN tablenames
WHERE condition
GROUP BY yourcolumns
HAVING aggregatecolumn condition
ORDER BY yourcolumns

What is Session Identifier?

Session Identifier is used to identify session. It has SessionId property. When a page is requested, browser sends a cookie with a session identifier. This identifier is used by the web server to determine if it belongs to an existing session or not. If not, a Session ID (120 - bit string) is generated by the web server and sent along with the response.

Difference between Session object and Profile object in ASP.NET?


Profile
-------
1.Profile object is persistent.
2.Profile object uses the provider model to store information.
3. Profile object is strongly typed.
4. Mostly used for anonymous users.

Session 
--------
1.Session object is non-persistant.
2.Session object uses the In Proc, Out Of Process or SQL Server Mode to store information.
3. Session object is not strongly typed.
4. Used for authenticated users.

difference between Char Vs nChar Vs Varchar


Char :
Fix length memory storage
Char takes up 1 byte per character

NChar : Nchar takes Unicode data

Varchar :
Variable length memory storage
varchar rakes 1 byte for character and +2 bytes to hold length information

Difference between debug and trace


Trace statements are included by default when the program is compiled in to release build,where as debug statements are not.The Debug class is used for debugging,however, the Trace class is used for testing and optimization even after an application is compiled and released.

What is difference between interface inheritance and class inheritance

interface inheritance is a misleading term. Interface inheritance would be equivalent to the union of the method signatures of interfaces ( no typo here, an interface may implment multiple other interfaces)

Class inheritance - single hierarchy (in C#), and not only the methods are inherited, but also the data members. (interface in C# cannot define data members)

What is dataset and tell about its features. What are equivalent methods of previous, next etc. Of ADO in ADO.NET

Plz provide the answer

What are WSDL ports


 element defines an individual endpoint by specifying a single address for a binding.
Here is the grammer to specify a port:

    



  • The port element has two attributes - the name attribute and the binding attribute.
  • The name attribute provides a unique name among all ports defined within in the enclosing WSDL document.
  • The binding attribute refers to the binding using the linking rules defined by WSDL.
  • Binding extensibility elements (1) are used to specify the address information for the port.
  • A port MUST NOT specify more than one address.
  • A port MUST NOT specify any binding information other than address information.

What is the difference between session state and session variables

Plz give your answer

What are the different types of caching?

Output Caching: Output caching is useful when the contents of an entire page can be cached. While a page is cached by the output cache, subsequent requests for that page are served from the output page without executing the code that created it.

Fragment Caching: Sometimes it is not practical to cache an entire page - perhaps portions of the page must be created or customized for each request. In this case, it is often worthwhile to identify objects or data that are expensive to construct and are eligible for caching. Once these items are identified, they can be created once and then cached for some period of time. Additionally, fragment caching can be used to cache regions of a page's output.

Data Caching: Data caching is storing data in memory for quick access. Typically information that is costly to obtain (in terms of performance) is stored in the cache. One of the more common items stored in a cache is commonly displayed database values; by caching such information, rather than relying on repeated database calls, the demand on the Web server and database server's system resources are decreased and the Web application's scalability increased. The cache items can be given an expiration policy that causes them to be removed from the cache when they have expired. Code that accesses the cache item simply checks for the absence of the item and recreates it, if necessary.

Thursday, August 30, 2012

what are the advantages of hosting WCF Services in IIS as compared to self-hosting?

There are two main advantages of using IIS over self-hosting:-
Automatic activation
IIS provides automatic activation that means the service is not necessary to be running in
advance. When any message is received by the service it then launches and fulfills the request.
But in case of self hosting the service should always be running.
Process recycling
If IIS finds that a service is not healthy that means if it has memory leaks etc, IIS recycles the
process. For every browser instance, a
worker process is spawned and the request is serviced. When the browser disconnects the worker,
process stops and you loose all information. IIS also restarts the worker process. By default, the
worker process is recycled at around 120 minutes. So why does IIS recycle. By restarting the
worker process it ensures any bad code or memory leak do not cause issue to the whole system.
In case of self-hosting both the above features, you will need to code yourself. Lot of work
right!!.

How to generate proxy for WCF Services?

The proxy can be generated using Visual Studio by right clicking Reference and clicking on Add Service Reference. This brings up the Add Service Reference dialog box, where you need to supply the base address of the service (or a base address and a MEX URI) and the namespace to contain the proxy.
Proxy can also be generated by using SvcUtil.exe command-line utility. We need to provide SvcUtil with the HTTP-GET address or the metadata exchange endpoint address and, optionally, with a proxy filename. The default proxy filename is output.cs but you can also use the /out switch to indicate a different name.
SvcUtil http://localhost/MyService/MyService.svc /out:Proxy.cs
When we are hosting in IIS and selecting a port other than port 80 (such as port 88), we must provide that port number as part of the base address:
SvcUtil http://localhost:88/MyService/MyService.svc /out:Proxy.cs

What are SOAP Faults in WCF?

Common language runtime (CLR) exceptions do not flow across service boundaries. At the maximum, a CLR exceptions may propagate up to the service tier from business components. Unhandled CLR exceptions reach the service channel and are serialized as SOAP faults before reporting to clients. An unhandled CLR exception will fault the service channel, taking any existing sessions with it. That is why it is very importatnt to convert the CLR exceptions into SOAP faults. Where possible, throw fault exceptions

What is the proxy for WCF Service?

A proxy is a class by which a service client can Interact with the service.
By the use of proxy in the client application we are able to call the different methods exposed by the service

What are the types of contract available in WCF?

The main contracts are:
a)Service Contract:Describes what operations the client can perform.
b)Operation Contract : defines the method inside Interface of Service.
c)Data Contract:Defines what data types are passed
d)Message Contract:Defines wheather a service can interact directly with messages

In WCF which bindings supports the reliable session?

In WCF, following bindings supports the reliable session - 

1. wsHttpBinding 
2. wsDualHttpBinding 
3. wsFederationHttpBinding 
4. netTcpBinding 

What are the advantages of hosting WCF service in WAS?

WAS (Windows Activation Service) is a component of IIS 7.0. Following are few advantages : 

1. We are not only limited to HTTP protocol. We can also use supported protocols like TCP, named pipes and MSMQ 

2. No need to completely install IIS. We can only install WAS component and keep away the WebServer. 

What is service host factory in WCF?

1. Service host factory is the mechanism by which we can create the instances of service host dynamically as the request comes in. 
2. This is useful when we need to implement the event handlers for opening and closing the service. 
3. WCF provides ServiceFactory class for this purpose. 

What are the core security features that WCF addresses?

There are four core security features that WCF addresses:-

Confidentiality: This feature ensures that the information does not go in wrong hands when it travels from the sender to the receiver.

Integrity: This feature ensures that the receiver of the message gets the same information that the sender sends without any data tampering. 

Authentication: This feature verifies who the sender is and who the receiver is. 

Authorization: This feature verifies whether the user is authorized to perform the action they are requesting from the application.


What the different transaction options ?

There are three transaction option in wcf :

TransactionFlowOption.NotAllowed

This is a default option. Using this option no transaction will be propagated across the binding. If any client attempts to call the WCF service in a transaction it will be ignored for this option.

TransactionFlowOption.Allowed

This option specifies that client can call this WCF service in a transaction. It’s not compulsory that the service needs to be called in a transaction. You can call without the transaction also.

TransactionFlowOption.Mandatory

This option specifies that client must call the WCF service in a transaction mode. If the WCF service is called without transaction, ‘FaultException’ will be raised.

What are the major differences between services and Web services? OR What is the difference WCF and Web services?

Web services can only be invoked by HTTP. While Service or a WCF component can be invoked by any protocol and any transport type. Second web services are not flexible. However, Services are flexible. If you make a new version of the service then you need to just expose a new end. Therefore, services are agile and which is a very practical approach looking at the current business trends.

What is wcf ?

The Windows Communication Foundation (or WCF), previously known as "Indigo", is a runtime and a set of APIs (application programming interface) in the .NET Framework for building connected, service-oriented applications.


What are ends, contracts, address and bindings?


• Contract (What)Contract is an agreement between two or more parties. It defines the protocol how client should communicate with your service. Technically, it describes parameters and return values for a method.
 

• Address (Where)An Address indicates where we can find this service. Address is a URL, which points to the location of the service.
 

• Binding (How)Bindings determine how this end can be accessed. It determines how communications is done. For instance, you expose your service, which can be accessed using SOAP over HTTP or BINARY over TCP. So for each of these communications medium two bindings will be created.
Below figure, show the three main components of end. You can see the stock ticker is the service class, which has an end hosted on www.soa.com with HTTP and TCP binding support and using Stock Ticker interface type.
 

constructor chaining

where a constructor calls another constructor in its class using the ": this()" designation as 


public Test( bool a, int b, string c )
    : this( a, b )
{
    this.m_C = c;
}
public Test( bool a, int b, float d )
    : this( a, b )
{
    this.m_D = d;
}
private Test( bool a, int b )
{
    this.m_A = a;
    this.m_B = b;
}

Basically constructor chaining is where a subclass calls its superclasses constructor which subsequentally calls its superclasses constrctor and so on.

Difference between # and ## in sql server ?


#table refers to a local (visible to only the user who created it) temporary table.

##table refers to a global (visible to all users) temporary table.

Wednesday, August 29, 2012

What is the difference between user and custom controls?


User controls are easier to create whereas custom controls require extra effort.
User controls are used when the layout is static whereas custom controls are used in dynamic layouts.
A user control cannot be added to the toolbox whereas a custom control can be.
A separate copy of a user control is required in every application that uses it whereas since custom controls are stored in the GAC, only a single copy can be used by all applications.

Why don’t we have multiple inheritance in .NET?


There are several reasons for this. In simple words, the efforts are more, benefits are less. Different languages have different implementation requirements of multiple inheritance. So in order to implement multiple inheritance, we need to study the implementation aspects of all the languages that are CLR compliant and then implement a common methodology of implementing it. This is too much of efforts. Moreover multiple interface inheritance very much covers the benefits that multiple inheritance has.

HttpContext


HttpContext object will hold information about the current http request. HttpContext object will be constructed newly for every request given to an ASP.Net application and this object will hold current request specific informations like Request, Response, Server, Session, Cache, User and etc. For every request, a new HttpContext object will be created which the ASP.Net runtime will use during the request processing. A new HttpContext object will be created at the beginning of a request and destroyed when the request is completed.
One of the best features of HttpContext object is using its Item Collection.

Array


An array is a fixed collection of same-type data that are stored contiguously.
Arrays are declared much like variables, with a set of [] brackets after the data type, like this: 

You need to instantiate the array to use it, which is done like this: 

string[] names = new string[2];

Differrence between Array.CopyTo() and Array.Clone()

Both CopyTo() and Clone() make shallow copy (data is copied) and used for Single Dimension arrays.

Clone() method makes a clone of the original array. It returns an exact length array.

CopyTo()
 copies the elements from the original array to the destination array starting at the specified destination array index. Note that, this adds elements to an already existing array.

Difference between delete and truncate in sql server?

TruncateDelete
TRUNCATE is a DDL commandDELETE is a DML command
TRUNCATE TABLE always locks the table and page but not each rowDELETE statement is executed using a row lock,                                             each row in the table is locked for deletion
Cannot use Where ConditionWe can specify filters in where clause
It Removes all the dataIt deletes specified data if where condition exists.
TRUNCATE TABLE cannot activate a trigger because the operation does not log individual row deletions.Delete activates a trigger because the operation                                are logged individually.
Faster in performance wise, because it is minimally logged in transaction log.Slower than truncate because, it maintain logs for every record
 Drop all object’s statistics and marks like High Water Mark free extents and leave the object really empty with the first extent. zero pages are left in the tablekeeps object’s statistics and all allocated space. After a                       DELETE statement is executed,the table can still contain empty pages.
TRUNCATE TABLE removes the data by deallocating the data pages used to store the table data and records only the page deallocations in the transaction loThe DELETE statement removes rows one at a time                       and records an entry in the transaction log for each deleted row
If the table contains an identity column, the counter for that column is reset to the seed value that is defined for the columnDELETE retain the identity
Restrictions on using Truncate Statement
1. Are referenced by a FOREIGN KEY constraint.
2. Participate in an indexed view.
3. Are published by using transactional replication or merge replication.
Delete works at row level, thus row level constrains apply

What is the difference between stored procedure and function.

1) Stored procedure are compiled for first time and compiled format is saved and executes compiled code when ever it is called. But function is compiled and executed every time it is called. 

2) Function must return a value but in stored procedure it is optional. 

3) Function takes one input parameter it is mandatory but stored procedure may take o to n input parameters.

4) Functions can be called from select statement, but stored procedures can not be called from select statement. 

5) We can use try catch statements in stored procedures but in functions we can not use.

6) We can not use insert,delete,update and create statements in functions but in stored procedures we can use those statements. 

7 ) Functions can have only input parameters but stored procedure can have input and out put parameters

What is Singleton ?


Singleton class is a class whose only one object can be created at a time
Singleton provides a global, single instance by:

·  Making the class create a single instance of itself.

·  Allowing other objects to access this instance through a class method that returns a reference to the instance. A class method is globally accessible.

·   Declaring the class constructor as private so that no other object can create a new instance.

Singleton results in the following benefits and liabilities:

               Benefits

·   Instance control. Singleton prevents other objects from instantiating their own copies of the Singleton object, ensuring that all objects access the single instance.

·   Flexibility. Because the class controls the instantiation process, the class has the flexibility to change the instantiation process.

Liabilities

·   Overhead. Although the amount is minuscule, there is some overhead involved in checking whether an instance of the class already exists every time an object requests a reference. This problem can be overcome by using static initialization as described in Implementing Singleton in C#.

·   Possible development confusion. When using a singleton object (especially one defined in a class library), developers must remember that they cannot use the new keyword to instantiate the object. Because application developers may not have access to the library source code, they may be surprised to find that they cannot instantiate this class directly.

·   Object lifetime. Singleton does not address the issue of deleting the single object. In languages that provide memory management (for example, languages based on the .NET Framework), only the Singleton class could cause the instance to be deallocated because it holds a private reference to the instance. In languages, such as C++, other classes could delete the object instance, but doing so would lead to a dangling reference inside the Singleton class.

What is Indexer ?


Indexer : Indexers allow your class to be used just like an array.
·         Indexer Concept is object act as an array.
Indexer an object to be indexed in the same way as an array.
·         Indexer modifier can be private, public, protected or internal.
·         The return type can be any valid C# types.
·         Indexers in C# must have at least one parameter. Else the compiler will generate a compilation error.

this [Parameter]
{
    get
    {
        // Get codes goes here
    }
    set
    {
        // Set codes goes here
    }

For Example:

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

namespace Indexers
{
    class ParentClass
    {
        private string[] range = new string[5];
        public string this[int indexrange]
        {
            get
            {
                return range[indexrange];
            }
            set
            {
                range[indexrange] = value;
            }
        }
    }

    /* The Above Class just act as array declaration using this pointer */

    class childclass
    {
        public static void Main()
        {
            ParentClass obj = new ParentClass();

            /* The Above Class ParentClass  create one object name is obj */

            obj[0] = "ONE";
            obj[1] = "TWO";
            obj[2] = "THREE";
            obj[3] = "FOUR ";
            obj[4] = "FIVE";
            Console.WriteLine("WELCOME TO C# CORNER HOME PAGE\n");
            Console.WriteLine("\n");

            Console.WriteLine("{0}\n,{1}\n,{2}\n,{3}\n,{4}\n", obj[0], obj[1], obj[2], obj[3], obj[4]);
            Console.WriteLine("\n");
            Console.WriteLine("ALS.Senthur Ganesh Ram Kumar\n");
            Console.WriteLine("\n");
            Console.ReadLine();
        }
    }
}

Why we use property in c#? (get, set)


Properties are a way to control access to your private members. It simply (set) copies the given value to the private member and (get) returns the private member without modifying it. Often, the set part is used to check the given value in order to avoid later errors, or to simplify code

private string myString = "";

public string MyString
{
set
{ if ( value == null )
{value = "";}
myString = value;
}
}

Document Object Model (DOM)


The Document Object Model (DOM) is a cross-platform and language-independent convention for representing and interacting with objects in HTML, XHTML and XML documents
The DOM is separated into 3 different parts / levels:


  • Core DOM - standard model for any structured document
  • XML DOM - standard model for XML documents
  • HTML DOM - standard model for HTML documents
What is the XML DOM?
  • A standard object model for HTML
  • A standard programming interface for HTML
  • Platform- and language-independent
  • A W3C standard
All XML Elements Must Have a Closing TagXML Tags are Case SensitiveXML Elements Must be Properly NestedXML Documents Must Have a Root Element
    .....
  • The entire document is a document node
  • Every HTML element is an element node
  • The text in the HTML elements are text nodes
  • Every HTML attribute is an attribute node
  • Comments are comment nodes
DOM Example                    DOM Lesson one     Hello world!   The HTML DOM Node Tree
  • x.innerHTML - the text value of x
  • x.nodeName - the name of x
  • x.nodeValue - the value of x
  • x.parentNode - the parent node of x
  • x.childNodes - the child nodes of x
  • x.attributes - the attributes nodes of x

  • x.getElementById(id) - get the element with a specified id
  • x.getElementsByTagName(name) - get all elements with a specified tag name
  • x.appendChild(node) - insert a child node to x
  • x.removeChild(node) - remove a child node from x


The XML DOM defines the objects and properties of all XML elements, and the methods (interface) to access them.
What is the HTML DOM?
The HTML DOM is:
The HTML DOM defines the objects and properties of all HTML elements, and the methods(interface) to access them.

 

DOM Nodes
According to the DOM, everything in an HTML document is a node.
The DOM says:
Look at the following HTML document:


The HTML DOM views an HTML document as a tree-structure. The tree structure is called a node-tree.
All nodes can be accessed through the tree. Their contents can be modified or deleted, and new elements can be created.

The programming interface of the DOM is defined by standard properties and methods.
Properties are often referred to as something that is (i.e. the name of a node).
Methods are often referred to as something that is done (i.e. remove a node).

HTML DOM Properties
Some DOM properties:
Note: In the list above, x is a node object (HTML element).

HTML DOM Methods
Some DOM methods:
Note: In the list above, x is a node object (HTML element).