### Articles On Testing

Wecome to http://www.articlesontesting.com !!!

### Articles On Testing

Wecome to http://www.articlesontesting.com !!!

### Articles On Testing

Wecome to http://www.articlesontesting.com !!!

### Articles On Testing

Wecome to http://www.articlesontesting.com !!!

### Articles On Testing

Wecome to http://www.articlesontesting.com !!!

### MySql Commands Names

Here are listed the most commonly used MYSQL Statements and clauses , mysql commands

ALTER DATABASE

ALTER TABLE

ALTER VIEW

ANALYZE TABLE

BACKUP TABLE

CACHE INDEX

CHANGE MASTER TO

CHECK TABLE

CHECKSUM TABLE

COMMIT

CREATE DATABASE

CREATE INDEX

CREATE TABLE

CREATE VIEW

DELETE

DESCRIBE

DO

DROP DATABASE

DROP INDEX

DROP TABLE

DROP USER

DROP VIEW

EXPLAIN

FLUSH

GRANT

HANDLER

INSERT

JOIN

KILL

LOCK TABLES

OPTIMIZE TABLE

PURGE MASTER LOGS

RENAME TABLE

REPAIR TABLE

REPLACE

RESET

RESET MASTER

RESET SLAVE

RESTORE TABLE

REVOKE

ROLLBACK

ROLLBACK TO SAVEPOINT

SAVEPOINT

SELECT

SET

SET SQL_LOG_BIN

SET TRANSACTION

SHOW BINLOG EVENTS

SHOW CHARACTER SET

SHOW COLLATION

SHOW COLUMNS

SHOW CREATE DATABASE

SHOW CREATE TABLE

SHOW CREATE VIEW

SHOW DATABASES

SHOW ENGINES

SHOW ERRORS

SHOW GRANTS

SHOW INDEX

SHOW INNODB STATUS

SHOW LOGS

SHOW MASTER LOGS

SHOW MASTER STATUS

SHOW PRIVILEGES

SHOW PROCESSLIST

SHOW SLAVE HOSTS

SHOW SLAVE STATUS

SHOW STATUS

SHOW TABLE STATUS

SHOW TABLES

SHOW VARIABLES

SHOW WARNINGS

START SLAVE

START TRANSACTION

STOP SLAVE

TRUNCATE TABLE

UNION

UNLOCK TABLES

USE

String Functions

AES_DECRYPT

AES_ENCRYPT

ASCII

BIN

BINARY

BIT_LENGTH

CHAR

CHAR_LENGTH

CHARACTER_LENGTH

COMPRESS

CONCAT

CONCAT_WS

CONV

DECODE

DES_DECRYPT

DES_ENCRYPT

ELT

ENCODE

ENCRYPT

EXPORT_SET

FIELD

FIND_IN_SET

HEX

INET_ATON

INET_NTOA

INSERT

INSTR

LCASE

LEFT

LENGTH

LOCATE

LOWER

LTRIM

MAKE_SET

MATCH AGAINST

MD5

MID

OCT

OCTET_LENGTH

ORD

POSITION

QUOTE

REPEAT

REPLACE

REVERSE

RIGHT

RTRIM

SHA

SHA1

SOUNDEX

SPACE

STRCMP

SUBSTRING

SUBSTRING_INDEX

TRIM

UCASE

UNCOMPRESS

UNCOMPRESSED_LENGTH

UNHEX

UPPER

Date and Time Functions

CONVERT_TZ

CURDATE

CURRENT_DATE

CURRENT_TIME

CURRENT_TIMESTAMP

CURTIME

DATE

DATE_FORMAT

DATE_SUB

DATEDIFF

DAY

DAYNAME

DAYOFMONTH

DAYOFWEEK

DAYOFYEAR

EXTRACT

FROM_DAYS

FROM_UNIXTIME

GET_FORMAT

HOUR

LAST_DAY

LOCALTIME

LOCALTIMESTAMP

MAKEDATE

MAKETIME

MICROSECOND

MINUTE

MONTH

MONTHNAME

NOW

PERIOD_DIFF

QUARTER

SEC_TO_TIME

SECOND

STR_TO_DATE

SUBDATE

SUBTIME

SYSDATE

TIME

TIMEDIFF

TIMESTAMP

TIMESTAMPDIFF

TIME_FORMAT

TIME_TO_SEC

TO_DAYS

UNIX_TIMESTAMP

UTC_DATE

UTC_TIME

UTC_TIMESTAMP

WEEK

WEEKDAY

WEEKOFYEAR

YEAR

YEARWEEK

Mathematical and Aggregate Functions

ABS

ACOS

ASIN

ATAN

ATAN2

AVG

BIT_AND

BIT_OR

BIT_XOR

CEIL

CEILING

COS

COT

COUNT

CRC32

DEGREES

EXP

FLOOR

FORMAT

GREATEST

GROUP_CONCAT

LEAST

LN

LOG

LOG2

LOG10

MAX

MIN

MOD

PI

POW

POWER

RAND

ROUND

SIGN

SIN

SQRT

STD

STDDEV

SUM

TAN

TRUNCATE

VARIANCE

Flow Control Functions

CASE

IF

IFNULL

NULLIF

Command-Line Utilities

comp_err

isamchk

make_binary_distribution

msql2mysql

my_print_defaults

myisamchk

myisamlog

myisampack

mysqlaccess

mysqlbinlog

mysqlbug

mysqlcheck

mysqldump

mysqldumpslow

mysqlhotcopy

mysqlimport

mysqlshow

perror

Perl API - using functions and methods built into the Perl DBI with MySQL

available_drivers

begin_work

bind_col

bind_columns

bind_param

bind_param_array

bind_param_inout

can

clone

column_info

commit

connect

connect_cached

data_sources

disconnect

do

dump_results

err

errstr

execute

execute_array

execute_for_fetch

fetch

fetchall_arrayref

fetchall_hashref

fetchrow_array

fetchrow_arrayref

fetchrow_hashref

finish

foreign_key_info

func

get_info

installed_versions

last_insert_id

looks_like_number

neat

neat_list

parse_dsn

parse_trace_flag

parse_trace_flags

ping

prepare

prepare_cached

primary_key

primary_key_info

quote

quote_identifier

rollback

rows

selectall_arrayref

selectall_hashref

selectcol_arrayref

selectrow_array

selectrow_arrayref

selectrow_hashref

set_err

state

table_info

table_info_all

tables

trace

trace_msg

type_info

type_info_all

Attributes for Handles

PHP API - using functions built into PHP with MySQL

mysql_affected_rows

mysql_change_user

mysql_client_encoding

mysql_close

mysql_connect

mysql_create_db

mysql_data_seek

mysql_db_name

mysql_db_query

mysql_drop_db

mysql_errno

mysql_error

mysql_escape_string

mysql_fetch_array

mysql_fetch_assoc

mysql_fetch_field

mysql_fetch_lengths

mysql_fetch_object

mysql_fetch_row

mysql_field_flags

mysql_field_len

mysql_field_name

mysql_field_seek

mysql_field_table

mysql_field_type

mysql_free_result

mysql_get_client_info

mysql_get_host_info

mysql_get_proto_info

mysql_get_server_info

mysql_info

mysql_insert_id

mysql_list_dbs

mysql_list_fields

mysql_list_processes

mysql_list_tables

mysql_num_fields

mysql_num_rows

mysql_pconnect

mysql_ping

mysql_query

mysql_real_escape_string

mysql_result

mysql_select_db

mysql_stat

mysql_tablename

mysql_unbuffered_query

### MySql Commands

This is a list of handy MySQL commands that I use time and time again. At the bottom are statements, clauses, and functions you can use in MySQL. Below that are PHP and Perl API functions you can use to interface with MySQL. To use those you will need to build PHP with MySQL functionality. To use MySQL with Perl you will need to use the Perl modules DBI and DBD::mysql.

Below when you see # it means from the unix shell. When you see mysql> it means from a MySQL prompt after logging into MySQL.
To login (from unix shell) use -h only if needed.

# [mysql dir]/bin/mysql -h hostname -u root -p
Create a database on the sql server.

mysql> create database [databasename];
List all databases on the sql server.

mysql> show databases;
Switch to a database.

mysql> use [db name];
To see all the tables in the db.

mysql> show tables;
To see database's field formats.

mysql> describe [table name];
To delete a db.

mysql> drop database [database name];
To delete a table.

mysql> drop table [table name];
Show all data in a table.

mysql> SELECT * FROM [table name];
Returns the columns and column information pertaining to the designated table.

mysql> show columns from [table name];
Show certain selected rows with the value "whatever".

mysql> SELECT * FROM [table name] WHERE [field name] = "whatever";
Show all records containing the name "Bob" AND the phone number '3444444'.

mysql> SELECT * FROM [table name] WHERE name = "Bob" AND phone_number = '3444444';
Show all records not containing the name "Bob" AND the phone number '3444444' order by the phone_number field.

mysql> SELECT * FROM [table name] WHERE name != "Bob" AND phone_number = '3444444' order by phone_number;
Show all records starting with the letters 'bob' AND the phone number '3444444'.

mysql> SELECT * FROM [table name] WHERE name like "Bob%" AND phone_number = '3444444';
Show all records starting with the letters 'bob' AND the phone number '3444444' limit to records 1 through 5.

mysql> SELECT * FROM [table name] WHERE name like "Bob%" AND phone_number = '3444444' limit 1,5;
Use a regular expression to find records. Use "REGEXP BINARY" to force case-sensitivity. This finds any record beginning with a.

mysql> SELECT * FROM [table name] WHERE rec RLIKE "^a";
Show unique records.

mysql> SELECT DISTINCT [column name] FROM [table name];
Show selected records sorted in an ascending (asc) or descending (desc).

mysql> SELECT [col1],[col2] FROM [table name] ORDER BY [col2] DESC;
Return number of rows.

mysql> SELECT COUNT(*) FROM [table name];
Sum column.

mysql> SELECT SUM(*) FROM [table name];
Join tables on common columns.

mysql> select lookup.illustrationid, lookup.personid,person.birthday from lookup left join person on lookup.personid=person.personid=statement to join birthday in person table with primary illustration id;
Creating a new user. Login as root. Switch to the MySQL db. Make the user. Update privs.

# mysql -u root -p
mysql> use mysql;
mysql> flush privileges;
Change a users password from unix shell.

# mysql -u root -p
mysql> flush privileges;
Recover a MySQL root password. Stop the MySQL server process. Start again with no grant tables. Login to MySQL as root. Set new password. Exit MySQL and restart MySQL server.

# /etc/init.d/mysql stop
# mysqld_safe --skip-grant-tables &
# mysql -u root
mysql> use mysql;
mysql> flush privileges;
mysql> quit
# /etc/init.d/mysql stop
# /etc/init.d/mysql start

Allow the user "bob" to connect to the server from localhost using the password "passwd". Login as root. Switch to the MySQL db. Give privs. Update privs.

# mysql -u root -p
mysql> use mysql;
mysql> grant usage on *.* to bob@localhost identified by 'passwd';
mysql> flush privileges;
Give user privilages for a db. Login as root. Switch to the MySQL db. Grant privs. Update privs.

# mysql -u root -p
mysql> use mysql;
mysql> INSERT INTO db (Host,Db,User,Select_priv,Insert_priv,Update_priv,Delete_priv,Create_priv,Drop_priv) VALUES ('%','databasename','username','Y','Y','Y','Y','Y','N');
mysql> flush privileges;

or

mysql> grant all privileges on databasename.* to username@localhost;
mysql> flush privileges;
To update info already in a table.

mysql> UPDATE [table name] SET Select_priv = 'Y',Insert_priv = 'Y',Update_priv = 'Y' where [field name] = 'user';
Delete a row(s) from a table.

mysql> DELETE from [table name] where [field name] = 'whatever';
Update database permissions/privilages.

mysql> flush privileges;
Delete a column.

mysql> alter table [table name] drop column [column name];
Add a new column to db.

mysql> alter table [table name] add column [new column name] varchar (20);
Change column name.

mysql> alter table [table name] change [old column name] [new column name] varchar (50);
Make a unique column so you get no dupes.

mysql> alter table [table name] add unique ([column name]);
Make a column bigger.

mysql> alter table [table name] modify [column name] VARCHAR(3);
Delete unique from table.

mysql> alter table [table name] drop index [colmn name];
Load a CSV file into a table.

mysql> LOAD DATA INFILE '/tmp/filename.csv' replace INTO TABLE [table name] FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n' (field1,field2,field3);
Dump all databases for backup. Backup file is sql commands to recreate all db's.

# [mysql dir]/bin/mysqldump -u root -ppassword --opt >/tmp/alldatabases.sql
Dump one database for backup.

Dump a table from a database.

Restore database (or database table) from backup.

# [mysql dir]/bin/mysql -u username -ppassword databasename < /tmp/databasename.sql Create Table Example 1. mysql> CREATE TABLE [table name] (firstname VARCHAR(20), middleinitial VARCHAR(3), lastname VARCHAR(35),suffix VARCHAR(3),officeid VARCHAR(10),userid VARCHAR(15),username VARCHAR(8),email VARCHAR(35),phone VARCHAR(25), groups VARCHAR(15),datestamp DATE,timestamp time,pgpemail VARCHAR(255));
Create Table Example 2.

mysql> create table [table name] (personid int(50) not null auto_increment primary key,firstname varchar(35),middlename varchar(50),lastnamevarchar(50) default 'bato');

### Algorithm Complexity -3

BIG O NOTATION
In mathematics, computer science, and related fields, big O notation  (also known as Big Oh notation, Landau notation, Bachmann–Landau notation, and asymptotic notation) describes the limiting behavior of a function when the argument tends towards a particular value or infinity, usually in terms of simpler functions. Big O notation allows its users to simplify functions in order to concentrate on their growth rates: different functions with the same growth rate may be represented using the same O notation.

Although developed as a part of pure mathematics, this notation is now frequently also used in the analysis of algorithms to describe an algorithm's usage of computational resources: the worst case or average case running time or memory usage of an algorithm is often expressed as a function of the length of its input using big O notation. This allows algorithm designers to predict the behavior of their algorithms and to determine which of multiple algorithms to use, in a way that is independent of computer architecture or clock rate. Because Big O notation discards multiplicative constants on the running time, and ignores efficiency for low input sizes, it does not always reveal the fastest algorithm in practice or for practically-sized data sets. But the approach is still very effective for comparing the scalability of various algorithms as input sizes become large.

A description of a function in terms of big O notation usually only provides an upper bound on the growth rate of the function. Associated with big O notation are several related notations, using the symbols o, Ω, ω, and Θ, to describe other kinds of bounds on asymptotic growth rates. Big O notation is also used in many other fields to provide similar estimates.

## Formal definition

Let f(x) and g(x) be two functions defined on some subset of the real numbers. One writes
$f(x)=O(g(x))\mbox{ as }x\to\infty\,$
if and only if, for sufficiently large values of x, f(x) is at most a constant multiplied by g(x) in absolute value. That is, f(x) = O(g(x)) if and only if there exists a positive real number M and a real number x0 such that
$|f(x)| \le \; M |g(x)|\mbox{ for all }x>x_0.$
In many contexts, the assumption that we are interested in the growth rate as the variable x goes to infinity is left unstated, and one writes more simply that f(x) = O(g(x)).
The notation can also be used to describe the behavior of f near some real number a (often, a = 0): we say
$f(x)=O(g(x))\mbox{ as }x\to a\,$
if and only if there exist positive numbers δ and M such that
$|f(x)| \le \; M |g(x)|\mbox{ for }|x - a| < \delta.$
If g(x) is non-zero for values of x sufficiently close to a, both of these definitions can be unified using the limit superior:
$f(x)=O(g(x))\mbox{ as }x \to a\,$
if and only if
$\limsup_{x\to a} \left|\frac{f(x)}{g(x)}\right| < \infty.$

## Example

In typical usage, the formal definition of O notation is not used directly; rather, the O notation for a function f(x) is derived by the following simplification rules:
• If f(x) is a sum of several terms, the one with the largest growth rate is kept, and all others omitted.
• If f(x) is a product of several factors, any constants (terms in the product that do not depend on x) are omitted.
For example, let f(x) = 6x4 − 2x3 + 5, and suppose we wish to simplify this function, using O notation, to describe its growth rate as x approaches infinity. This function is the sum of three terms: 6x4, −2x3, and 5. Of these three terms, the one with the highest growth rate is the one with the largest exponent as a function of x, namely 6x4. Now one may apply the second rule: 6x4 is a product of 6 and x4 in which the first factor does not depend on x. Omitting this factor results in the simplified form x4. Thus, we say that f(x) is a big-oh of (x4) or mathematically we can write f(x) = O(x4).
One may confirm this calculation using the formal definition: let f(x) = 6x4 − 2x3 + 5 and g(x) = x4. Applying the formal definition from above, the statement that f(x) = O(x4) is equivalent to its expansion,
$|f(x)| \le \; M |g(x)|$
for some suitable choice of x0 and M and for all x > x0. To prove this, let x0 = 1 and M = 13. Then, for all x > x0:
\begin{align}|6x^4 - 2x^3 + 5| &\le 6x^4 + |2x^3| + 5\\ &\le 6x^4 + 2x^4 + 5x^4\\ &= 13x^4,\\ &= 13|x^4|\end{align}
so
$|6x^4 - 2x^3 + 5| \le 13 \,|x^4 |.$

## Usage

Big O notation has two main areas of application. In mathematics, it is commonly used to describe how closely a finite series approximates a given function, especially in the case of a truncated Taylor series or asymptotic expansion. In computer science, it is useful in the analysis of algorithms. In both applications, the function g(x) appearing within the O(...) is typically chosen to be as simple as possible, omitting constant factors and lower order terms.
There are two formally close, but noticeably different, usages of this notation: infinite asymptotics and infinitesimal asymptotics. This distinction is only in application and not in principle, however—the formal definition for the "big O" is the same for both cases, only with different limits for the function argument.

### Infinite asymptotics

Big O notation is useful when analyzing algorithms for efficiency. For example, the time (or the number of steps) it takes to complete a problem of size n might be found to be T(n) = 4n2 − 2n + 2.
As n grows large, the n2 term will come to dominate, so that all other terms can be neglected — for instance when n = 500, the term 4n2 is 1000 times as large as the 2n term. Ignoring the latter would have negligible effect on the expression's value for most purposes.
Further, the coefficients become irrelevant if we compare to any other order of expression, such as an expression containing a term n3 or n4. Even if T(n) = 1,000,000n2, if U(n) = n3, the latter will always exceed the former once n grows larger than 1,000,000 (T(1,000,000) = 1,000,0003= U(1,000,000)). Additionally, the number of steps depends on the details of the machine model on which the algorithm runs, but different types of machines typically vary by only a constant factor in the number of steps needed to execute an algorithm.
So the big O notation captures what remains: we write either
$\ T(n)= O(n^2)$
or
$T(n)\in O(n^2)$
and say that the algorithm has order of n2 time complexity.
Note that "=" is not meant to express "is equal to" in its normal mathematical sense, but rather a more colloquial "is", so the second expression is technically accurate (see the "Equals sign" discussion below) while the first is a common abuse of notation.

### Infinitesimal asymptotics

Big O can also be used to describe the error term in an approximation to a mathematical function. The most significant terms are written explicitly, and then the least-significant terms are summarized in a single big O term. For example,
$e^x=1+x+\frac{x^2}{2}+O(x^3)\qquad\hbox{as}\ x\to 0$
expresses the fact that the error, the difference $\ e^x - (1 + x + x^2/2)$, is smaller in absolute value than some constant times | x3 | when x is close enough to 0.

## Properties

If a function f(n) can be written as a finite sum of other functions, then the fastest growing one determines the order of f(n). For example
$f(n) = 9 \log n + 5 (\log n)^3 + 3n^2 + 2n^3 \in O(n^3)\,\!.$
In particular, if a function may be bounded by a polynomial in n, then as n tends to infinity, one may disregard lower-order terms of the polynomial.
O(nc) and O(cn) are very different. The latter grows much, much faster, no matter how big the constant c is (as long as it is greater than one). A function that grows faster than any power of n is called superpolynomial. One that grows more slowly than any exponential function of the form cn is called subexponential. An algorithm can require time that is both superpolynomial and subexponential; examples of this include the fastest known algorithms for integer factorization.
O(logn) is exactly the same as O(log(nc)). The logarithms differ only by a constant factor (since log(nc) = clogn) and thus the big O notation ignores that. Similarly, logs with different constant bases are equivalent. Exponentials with different bases, on the other hand, are not of the same order. For example, 2n and 3n are not of the same order.
Changing units may or may not affect the order of the resulting algorithm. Changing units is equivalent to multiplying the appropriate variable by a constant wherever it appears. For example, if an algorithm runs in the order of n2, replacing n by cn means the algorithm runs in the order of c2n2, and the big O notation ignores the constant c2. This can be written as $c^2n^2 \in O(n^2)$. If, however, an algorithm runs in the order of 2n, replacing n with cn gives 2cn = (2c)n. This is not equivalent to 2n in general.
Changing of variable may affect the order of the resulting algorithm. For example, if an algorithm's running time is O(n) when measured in terms of the number n of digits of an input number x, then its running time is O(log x) when measured as a function of the input number x itself, because n = Θ(log x).

### Product

$f_1 \in O(g_1) \text{ and } f_2\in O(g_2)\, \Rightarrow f_1 f_2\in O(g_1 g_2)\,$
$f\cdot O(g) \in O(f g)$

### Sum

$f_1 \in O(g_1) \text{ and } f_2\in O(g_2)\, \Rightarrow f_1 + f_2\in O(|g_1| + |g_2|)\,$
This implies $f_1 \in O(g) \text{ and } f_2 \in O(g) \Rightarrow f_1+f_2 \in O(g)$, which means that O(g) is a convex cone.
If f and g are positive functions, $f + O(g) \in O(f + g)$

### Multiplication by a constant

Let k be a constant. Then:
$\ O(k g) = O(g)$if k is nonzero.
$f\in O(g) \Rightarrow kf\in O(g).$

## Multiple variables

Big O (and little o, and Ω…) can also be used with multiple variables.
To define Big O formally for multiple variables, suppose $f(\vec{x})$and $g(\vec{x})$are two functions defined on some subset of $\mathbb{R}^n$. We say
$f(\vec{x})\mbox{ is }O(g(\vec{x}))\mbox{ as }\vec{x}\to\infty$
if and only if
$\exists C\,\exists M>0\mbox{ such that } |f(\vec{x})| \le C |g(\vec{x})|\mbox{ for all }\vec{x} \mbox{ with } x_i>M \mbox{ for all }i.$
For example, the statement
$f(n,m) = n^2 + m^3 + \hbox{O}(n+m) \mbox{ as } n,m\to\infty\,$
asserts that there exist constants C and M such that
$\forall n, m>M\colon |g(n,m)| \le C(n+m),$
where g(n,m) is defined by
$f(n,m) = n^2 + m^3 + g(n,m).\,$
Note that this definition allows all of the coordinates of $\vec{x}$to increase to infinity. In particular, the statement
$f(n,m) = \hbox{O}(n^m) \mbox{ as } n,m\to\infty\,$
(i.e., $\exists C\,\exists M\,\forall n\,\forall m\dots$) is quite different from
$\forall m\colon f(n,m) = \hbox{O}(n^m) \mbox{ as } n\to\infty$
(i.e., $\forall m\,\exists C\,\exists M\,\forall n\dots$).

## Matters of notation

### Equals sign

The statement "f(x) is O(g(x))" as defined above is usually written as f(x) = O(g(x)). Some consider this to be an abuse of notation, since the use of the equals sign could be misleading as it suggests a symmetry that this statement does not have. As it is said, O(x) = O(x2) is true but O(x2) = O(x) is not.Knuth describes such statements as "one-way equalities", since if the sides could be reversed, "we could deduce ridiculous things like n = n2 from the identities n = O(n2) and n2 = O(n2)."
For these reasons, it would be more precise to use set notation and write f(x) ∈ O(g(x)), thinking of O(g(x)) as the class of all functions h(x) such that |h(x)| ≤ C|g(n)| for some constant C. However, the use of the equals sign is customary. Knuth pointed out that "mathematicians customarily use the = sign as they use the word 'is' in English: Aristotle is a man, but a man isn’t necessarily Aristotle."

### Other arithmetic operators

Big O notation can also be used in conjunction with other arithmetic operators in more complicated equations. For example, h(x) + O(f(x)) denotes the collection of functions having the growth of h(x) plus a part whose growth is limited to that of f(x). Thus,
$g(x) = h(x) + O(f(x))\,$
expresses the same as
$g(x) - h(x) \in O(f(x))\,.$

#### Example

Suppose an algorithm is being developed to operate on a set of n elements. Its developers are interested in finding a function T(n) that will express how long the algorithm will take to run (in some arbitrary measurement of time) in terms of the number of elements in the input set. The algorithm works by first calling a subroutine to sort the elements in the set and then perform its own operations. The sort has a known time complexity of O(n2), and after the subroutine runs the algorithm must take an additional 55n3 + 2n + 10 time before it terminates. Thus the overall time complexity of the algorithm can be expressed as
$T(n)=O(n^2)+55n^3+2n+10.\$
This can perhaps be most easily read by replacing O(n2) with "some function that grows asymptotically slower than n2 ". Again, this usage disregards some of the formal meaning of the "=" and "+" symbols, but it does allow one to use the big O notation as a kind of convenient placeholder.

### Declaration of variables

Another feature of the notation, although less exceptional, is that function arguments may need to be inferred from the context when several variables are involved. The following two right-hand side big O notations have dramatically different meanings:
$f(m) = O(m^n)\,,$
$g(n)\,\, = O(m^n)\,.$
The first case states that f(m) exhibits polynomial growth, while the second, assuming m > 1, states that g(n) exhibits exponential growth. To avoid confusion, some authors use the notation
$g \in O(f)\,,$
rather than the less explicit
$g(x) \in O(f(x))\,.$

### Complex usages

In more complex usage, O(...) can appear in different places in an equation, even several times on each side. For example, the following are true for $n\to\infty$
$(n+1)^2 = n^2 + O(n)\$
$(n+O(n^{1/2}))(n + O(\log n))^2 = n^3 + O(n^{5/2})\$
$n^{O(1)} = O(e^n).\$
The meaning of such statements is as follows: for any functions which satisfy each O(...) on the left side, there are some functions satisfying each O(...) on the right side, such that substituting all these functions into the equation makes the two sides equal. For example, the third equation above means: "For any function f(n) = O(1), there is some function g(n) = O(en) such that nf(n) = g(n)." In terms of the "set notation" above, the meaning is that the class of functions represented by the left side is a subset of the class of functions represented by the right side.

### Algorithm Complexity -2

Complexity measures
For a precise definition of what it means to solve a problem using a given amount of time and space, a computational model such as the deterministic Turing machine is used. The time required by a deterministic Turing machine M on input x is the total number of state transitions, or steps, the machine makes before it halts and outputs the answer ("yes" or "no"). A Turing machine M is said to operate within time f(n), if the time required by M on each input of length n is at most f(n). A decision problem A can be solved in time f(n) if there exists a Turing machine operating in time f(n) which solves the problem. Since complexity theory is interested in classifying problems based on their difficulty, one defines sets of problems based on some criteria. For instance, the set of problems solvable within time f(n) on a deterministic Turing machine is then denoted by DTIME(f(n)).

Analogous definitions can be made for space requirements. Although time and space are the most well-known complexity resources, any complexity measure can be viewed as a computational resource. Complexity measures are very generally defined by the Blum complexity axioms. Other complexity measures used in complexity theory include communication complexity, circuit complexity, and decision tree complexity.
 Best, worst and average case complexity
Visualization of the quicksort algorithm that has average case performance Θ(nlogn).

The best, worst and average case complexity refer to three different ways of measuring the time complexity (or any other complexity measure) of different inputs of the same size. Since some inputs of size n may be faster to solve than others, we define the following complexities:

* Best-case complexity: This is the complexity of solving the problem for the best input of size n.

* Worst-case complexity: This is the complexity of solving the problem for the worst input of size n.

* Average-case complexity: This is the complexity of solving the problem on an average. This complexity is only defined with respect to a probability distribution over the inputs. For instance, if all inputs of the same size are assumed to be equally likely to appear, the average case complexity can be defined with respect to the uniform distribution over all inputs of size n.

For example, consider the deterministic sorting algorithm quicksort. This solves the problem of sorting a list of integers which is given as the input. The best-case scenario is when the input is already sorted, and the algorithm takes time O(n log n) for such inputs. The worst-case is when the input is sorted in reverse order, and the algorithm takes time O(n2) for this case. If we assume that all possible permutations of the input list are equally likely, the average time taken for sorting is O(n log n).Upper and lower bounds on the complexity of problems

To classify the computation time (or similar resources, such as space consumption), one is interested in proving upper and lower bounds on the minimum amount of time required by the most efficient algorithm solving a given problem. The complexity of an algorithm is usually taken to be its worst-case complexity, unless specified otherwise. Analyzing a particular algorithm falls under the field of analysis of algorithms. To show an upper bound T(n) on the time complexity of a problem, one needs to show only that there is a particular algorithm with running time at most T(n). However, proving lower bounds is much more difficult, since lower bounds make a statement about all possible algorithms that solve a given problem. The phrase "all possible algorithms" includes not just the algorithms known today, but any algorithm that might be discovered in the future. To show a lower bound of T(n) for a problem requires showing that no algorithm can have time complexity lower than T(n).

Upper and lower bounds are usually stated using the big Oh notation, which hides constant factors and smaller terms. This makes the bounds independent of the specific details of the computational model used. For instance, if T(n) = 7n2 + 15n + 40, in big Oh notation one would write T(n) = O(n2).

### Algorithm Complexity -1

Computational complexity theory is a branch of the theory of computation in computer science and mathematics that focuses on classifying computational problems according to their inherent difficulty. In this context, a computational problem is understood to be a task that is in principle amenable to being solved by a computer. Informally, a computational problem consists of problem instances and solutions to these problem instances. For example, primality testing is the problem of determining whether a given number is prime or not. The instances of this problem are natural numbers, and the solution to an instance is yes or no based on whether the number is prime or not.
A problem is regarded as inherently difficult if solving the problem requires a large amount of resources, whatever the algorithm used for solving it. The theory formalizes this intuition, by introducing mathematical models of computation to study these problems and quantifying the amount of resources needed to solve them, such as time and storage. Other complexity measures are also used, such as the amount of communication (used in communication complexity), the number of gates in a circuit (used in circuit complexity) and the number of processors (used in parallel computing). In particular, computational complexity theory determines the practical limits on what computers can and cannot do.
Closely related fields in theoretical computer science are analysis of algorithms and computability theory. A key distinction between computational complexity theory and analysis of algorithms is that the latter is devoted to analyzing the amount of resources needed by a particular algorithm to solve a problem, whereas the former asks a more general question about all possible algorithms that could be used to solve the same problem. More precisely, it tries to classify problems that can or cannot be solved with appropriately restricted resources. In turn, imposing restrictions on the available resources is what distinguishes computational complexity from computability theory: the latter theory asks what kind of problems can be solved in principle algorithmically.

### VbScrirpt Registry Modification

This article describes how to fix the IconWindow shutdown problem using VBScript. The shutdown problem occurs on computers with the Symantec Ghost Client installed.

Step 1

Before making any changes to the registry we need to make a backup copy of the registry by exporting it. Open the registry editor by clicking on Start and clicking Run. Type "regedit" without the quotes and press 'Enter'

Step 2
Export the registry as PreIconWindowFix.reg by clicking on File, Export, and typing "PreIconWindowFix" without the quotes in the 'File name:' box. Make sure 'All' is selected under 'Export range' and click Save.

Step 3
Open Notepad by clicking on Start and clicking Run. Type "regedit" without the quotes and press 'Enter'

Step 4
Copy and paste the following script into Notepad:

strKey = "SOFTWARE\Microsoft\Windows\CurrentVersion\Run"
strValue = "NGTray"
strComputer = "."

Const HKLM = &H80000002

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")

'Deletes the registry entry which starts NGTray.exe
oReg.DeleteValue HKLM,strKey,strValue

Step 5
Save the file as IconWindowFix.vbs by clicking on File, Save As, and typing "IconWindowFix.vbs" without the quotes in the 'File name:' box. Next click the drop down arrow next to the 'Save as type:' box, select 'All Files', and click Save.

Step 6

Exit out of Notepad and double click on IconWindowFix.vbs to run the script.

### VbScript Environment, System Variables Reading

At times, when programming with vbscript, a programmer will want to read an existing environment variable.

This can be accomplished by accessing the Windows Script
Host via VBScript and making use of the shell object

The program example below will walk you through the steps necessary to accomplish this task and give you a real world example to learn from.

Step 1

1. Create a User Environment Variable
Create a user environment variable by right-clicking on "My Computer", selecting Properties - Advanced tab - Environment Variables and under User variables select New. This will open a New User Variable window. For Variable name:, type test. For Variable value:, type your name and select OK.

Go to Start - All Programs - Accessories - Notepad
#
Step 3

3. Copy Code
Copy and Paste the following code into Notepad.

'**************************************************************
Option explicit

'Declare Variables
Dim WshShl, Shell, UserVar

'Set objects
Set WshShl = WScript.CreateObject("WScript.Shell")
Set Shell = WshShl.Environment("User")

UserVar = Shell("Test")

'Output value to msgbox
WScript.Echo "Your name is " & UserVar & "!"

'Cleanup Objects
Set WshShl = Nothing
Set Shell = Nothing

'Exit Script
WScript.Quit()
'**************************************************************

4.Run Script

Browse to C:\Temp\ReadEnvVar.vbs using My Computer or Explore, depending on what you're use to.
Double-click on ReadEnvVar.vbs. You should get a message box as shown stating your name.

Select "OK"

4.      If you prefer to read a System environment variable, replace this line in your script

Set Shell = WshShl.Environment("User")
With this line
Set Shell = WshShl.Environment("System")

Replace this line
UserVar = Shell("Test")
With this line.
UserVar = Shell("Insert system variable you want to read here")

Replace this line
WScript.Echo "Your name is " & UserVar & "!"
With this line
WScript.Echo UserVar

So your vbscript makes sense, you may also want to replace the UserVar variable with SysVar, but your script should function just fine without this change.

Step 5
You've written a VBScript capable of reading a user or system environment variable.

### VbScript - File Checker

At times, when programming with VBScript, a programmer will want to know if a file exists prior to performing another function.

This is good programming practice and it can be accomplished by accessing the Windows Script Host via VBScript and making use of the FileSystemObject.

The program below will walk you through the steps necessary to accomplish this task and give you a real world example to learn from.

Create a file on your computer named test.txt at the following location C:\Temp\test.txt

This will be used to demonstrate the VBScript.Step 2

Go to Start - All Programs - Accessories - Notepad

Note: Adding .vbs to any .txt file creates an executable VBScript file.

Copy Code
Copy and Paste the following code into Notepad.

Run Script
Browse to C:\Temp\FileCheck.vbs using My Computer or Explore, depending on what you're use to.
Double-click on VBScript file "FileCheck.vbs". You should get a message box as shown below stating that the "File exists!". Select "OK"

Step 5

File does not exist!
Now rename or remove the following file C:\Temp\test.txt and Double-click on the FileCheck.vbs again.
This will create a condition where the file does not exist and you should get a message box which states "File does not exist!" Select "OK"

The If Then Else statement in the code above is doing the check and alerting you as to whether or not the file exists.

'**************************************************************
Option Explicit

'Set Dimension
DIM fso

'Set Object
Set fso = CreateObject("Scripting.FileSystemObject")

'Create Condition
If (fso.FileExists("C:\Temp\test.txt")) Then
WScript.Echo("File exists!")
WScript.Quit()
Else
WScript.Echo("File does not exist!")
End If

'Exit Script
WScript.Quit()
'**************************************************************

Step 4  Run Script

Browse to C:\Temp\FileCheck.vbs using My Computer or Explore, depending on what you're use to.
Double-click on VBScript file "FileCheck.vbs". You should get a message box as shown below stating that the "File exists!". Select "OK"

Now rename or remove the following file C:\Temp\test.txt and Double-click on the FileCheck.vbs again.
This will create a condition where the file does not exist and you should get a message box which states "File does not exist!" Select "OK".
The If Then Else statement in the code above is doing the check and alerting you as to whether or not the file exists.

### Vbscript - Remote Execution

VBScript can be written in any text-editing software, even Notepad. Learning the fine art of scripting can be beneficial to your job, especially, if you have to repeat the same processes over and over again. VBScripts can even be set to run in the middle of the night, on several computers, while you are at home sleeping the night away. There are mandatory files needed to run VBScript.

Instructions

2.      Create a variable named "strComputer" without the quotes.

3.      Point the variable to the local computer. By default the strComputer variable uses "." to represent the local computer. The code would be as follows:

strComputer = "."

This has to be changed to route the call to a remote computer.
If the remote computer Is named vipsrvr then the code would read:

strComputer = "vipsrvr"

This will allow you to run VBScript on the computer named vipsrvr.

4.      Run the script.

How to read a txt file using the VbScript programming ?

1.      Create a Text File
Create a text file with the following name at the following location.

Within the text file, add the following lines.
If you get this message,
you have successfully
completed this

Go to Start - All Programs - Accessories - Notepad

3.            Copy and Paste the following code into any Text Editor.

'*****************************************************************
Option Explicit

'Declare variables

'Set Objects
Set objFSO = CreateObject("Scripting.FileSystemObject")

'Close file

'Display results
wscript.echo contents

'Cleanup objects
Set objFSO = Nothing

'Quit script
WScript.Quit()
'******************************************************************

4. Execute the vbs file either from cmd prompt or by double clicking.

### QTP Action Versus Function

Actions vs Functions in QTP 9.0

When deciding whether a piece of code should go in a reusable action or a function, we usually favored functions in QTP 8.2. When Mercury introduced QuickTest 9, they made the argument for functions even more compelling with the Multi Document Interface. Now we can open as many function libraries as we want, but we are still limited to one test. So, if you want to edit a reusable action in another test, you have to close your current test, open the second test, make your changes, save and close the second test then reopen your original test.

In addition to that new argument for functions in QTP 9, the same old arguments from 8.2 still apply. I’ll sum up a few of the key differences between reusable actions and functions here.

Passing Data

Actions - can only accept primative data types as parameters (strings, integers, etc)

Functions - can accept arrays, dictionary objects and test objects (i.e. Pages, Frames, WebRadioGroups, etc.)

Resource Usage

Actions - For each action, there’s a folder, three separate vbs files, a local Object Repository, a subfolder containing snapshots, an Excel spreadsheet, and a few seconds of load time.

Functions - There’s the code contained in the Function, and that’s all

API

Actions - You cannot insert calls to Existing Actions through the QTP API, you can only do it through the interface

Functions - You can attach Function Libraries to Test Scripts through the QTP API

Return Values

Actions - Return values are difficult to understand and read in the syntax

Functions - Return values work like they do in other languages (i.e. as lvalues)

You cannot change the number of parameters that a function accepts without affecting
all calls to that function. That is a problem that used to drive me crazy. It seems like every time
I put a new function in a library, the next test I write needs that function with one extra option.
Now that I use the getopts function to define the parameters in my functions, I can easily add new
optional parameters without messing up other tests that already call the function.

### QTP Dom

What is Document object Model?
A platform- and language-independent standard object model for representing HTML or XML and related formats.

When can we use DOM?

One of the very important places you can use it is when a QTP web table checkpoint doesn’t show you the desired content in a cell. I mean the content in the cell is in a format that is not supported by the web table checkpoint. Another use can be when you want to access all the HTML tags used in a webpage. You can get the names, the innertext, innerHTML property of all these tags. The possibilities are endless.
How can we use DOM to access the source page?

We can access the source page of any webpage using .object notation.

Any practical example of using DOM?

I have created a demo web page to show you document object model in action. Say you want to find the font color used for writing Happy Holidays Everyone in cells of the webtable given on this page. The algorithm would be:

1. Access the DOM of webtable using .object notation.
2. Access the tagname corresponding to the property you wish to find out. In our case tagname is “font” and property to be explored is “color”.

3. Find the count of total number of tags and loop it find out the font-color.

The corresponding VB script would be:

set font=Browser("B").Page("P").WebTable("H").Object.all.tags("font")

msgbox font.length

For i=0 to font.length-1
Msgbox font(i).color
next

XML Code To Get Root Child Nodes

On error resume next
Set xmlDoc = XMLUtil.CreateXML()
If Err.Number <> 0 Then
Msgbox "Invalid XML"
End If
Set Root = xmlDoc.GetRootElement()
Set objChildNodes = Root.ChildElements()
numberof = objChildNodes.count()
msgbox numberof
On error goto 0

Encrypt PWD

str = "Some Text"
encrStr = Crypt.Encrypt(str)

### QTP Recipe is simple

You should learn the following:

VBScript
QTP uses VBScript language. That's why strong knowledge of VBScript is 'must have'.
Sources:

w3schools' VBScript tutorial
MS' VBScript Guide.

Software Testing Automation Frameworks
To write good automated tests, you should know how to write them.
There are different approaches and solution. There is not a silver bullet.
Sources:

Test Automation Frameworks
Choosing a Test Automation Framework
Totally Data-Driven Automated Testing
Seven Steps to Test Automation Success

HP QuickTest Professional Tutorial
This QTP tutorial cames with QTP.
It's quite clean and informative. Its main goal is to show and explain basic concepts of QuickTest Professional. It provides knowledge on:

creating a test
working with Object Repository (OR)
running and analyzing tests
verifying tests
parameterizing, etc

Sources: '\help\QTTutorial.pdf' or '\help\Tutorial.chm' in QTP Install folder.

HP QuickTest Professional User's Guide
As previous tutorial, the present User's Guide come with QTP install too.
This guide is intended for QuickTest Professional users at all levels. It gives a deeper knowledge on:

working with QTP Object Repositoies
designing tests
enhancing tests (checkpoints, parameterizing, etc)
maintaining anf debugging tests
Sources: '\help\QTUsersGuide.pdf' or '\help\MainUsersGuide.chm' in QTP Install folder.

COM/DCOM Technologies
When working with QTP, you will be closely linked with such Microsoft's applications, as: Excel, Word, Outlook. So, I recommend to get familiar with COM, COM Technologies, and COM objects of:

MS Internet Explorer
MS Excel
MS Outlook
SQL

SQL is so important in programming, that I strongly recommend to spend time to learn SQL:

concepts of RDBM
selecting/updating/deleting data
SQL queries optimizations

Sources:

w3schools' SQL tutorial
MS SQL Server - this and this
Oracle DB

XML

XML is an extremely popular and useful format. I'm sure that ?ou will have to deal with data, stored in XML-files.
Sources:

w3schools' XML tutorial

HTML, DOM
Since QuickTest Professional works perfectly with web applications, you should be expert in related fields - HTML, HTTP, DHTML, DOM, etc. They will simplify your future QTP script and make them more reliable and maintenable.
Sources:

w3schools' HTML tutorial
w3schools' DHTML tutorial
A Beginner's Guide to the XML DOM
DOM tutorials

HP QTP Knowledge Base
It contains a lot of practical articles about QuickTest Professional.
You can find there QTP webinars, QTP FAQs, documentations, solutions of your problems or different ways how to improve your QTP automated tests.
Sources:

Useful sites
Sure, it's impossible to know all information on QTP.
That's why I recommend to use these two sites to search answers to your QTP questions:

JMeter

Function getAllChildren3 ( object, type1, var1, type2, var2, type3, var3)

Set classVar = Description.Create()

classVar(type1).Value= var1

classVar(type2).Value= var2

classVar(type3).Value= var3

If type1 = "html tag" Then

classVar(type1).RegularExpression = false

End If

Set frameArray = object.ChildObjects(classVar)

If frameArray.Count-1 < 0 Then

msgbox "No objects found"

Else

For i = 0 to frameArray.Count -1

x = "Object item " & i+1 & " of " & frameArray.Count & vbNewLine

x = x & "html tag = " & frameArray(i).GetRoProperty("html tag") & vbNewLine

x = x & "name = " & frameArray(i).GetRoProperty("name") & vbNewLine

x = x & "html id = " & frameArray(i).GetRoProperty("html id") & vbNewLine

x = x & "url = " & frameArray(i).GetRoProperty("url") & vbNewLine

x = x & "class = "& frameArray(i).GetRoProperty("class") & vbNewLine

x = x & "innertext = " & frameArray(i).GetRoProperty("innertext") & vbNewLine

x = x & "outertext = " & frameArray(i).GetRoProperty("outertext") & vbNewLine

x = x & "text = " & frameArray(i).GetRoProperty("text") & vbNewLine

x = x & "href = " & frameArray(i).GetRoProperty("href") & vbNewLine

x = x & "innerhtml = " & frameArray(i).GetRoProperty("innerthtml") & vbNewLine

x = x & "outerhtml = " & frameArray(i).GetRoProperty("outerhtml") & vbNewLine

x = x & "src = " & frameArray(i).GetRoProperty("src") & vbNewLine

x = x & "file name = " & frameArray(i).GetRoProperty("file name")

msgbox x

Next

End If

classVar(type1).RegularExpression = True

End Function

### XML Part 1

The following JavaScript fragment loads an XML document
{
if (window.XMLHttpRequest)
{
xhttp=new XMLHttpRequest();
}
else
{
xhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xhttp.open("GET",dname,false);
xhttp.send();
return xhttp.responseXML;
}

The following code loads and parses an XML string:
if (window.DOMParser)
{
parser=new DOMParser();
xmlDoc=parser.parseFromString(text,"text/xml");
}
else // Internet Explorer
{
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async="false";
}
{
if (window.DOMParser)
{
parser=new DOMParser();
xmlDoc=parser.parseFromString(txt,"text/xml");
}
else // Internet Explorer
{
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async="false";
}
return xmlDoc;
}

XML DOM Properties
These are some typical DOM properties:
* 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
Note: In the list above, x is a node object.

XML DOM Methods
* 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
Note: In the list above, x is a node object.
The JavaScript code to get the text from the first element in books.xml:
txt=xmlDoc.getElementsByTagName("title")[0].childNodes[0].nodeValue
After the execution of the statement, txt will hold the value "Everyday Italian"
Explained:
* xmlDoc - the XML DOM object created by the parser.
* getElementsByTagName("title")[0] - the first element
* childNodes[0] - the first child of the element (the text node)
* nodeValue - the value of the node (the text itself)
Accessing Nodes
You can access a node in three ways:
1. By using the getElementsByTagName() method
2. By looping through (traversing) the nodes tree.
3. By navigating the node tree, using the node relationships.

* getElementsByTagName() returns all elements with a specified tag name.
x=xmlDoc.getElementsByTagName("title");

x=xmlDoc.getElementsByTagName("title");
for (i=0;i
{
document.write(x[i].childNodes[0].nodeValue);
document.write("
");
if (x[i].nodeType==1)
{//Process only element nodes (type 1)
document.write(x[i].nodeName);
document.write("
");
}
The following code navigates the node tree using the node relationships:
x=xmlDoc.getElementsByTagName("book")[0].childNodes;
y=xmlDoc.getElementsByTagName("book")[0].firstChild;
for (i=0;i
{
if (y.nodeType==1)
{//Process only element nodes (type 1)
document.write(y.nodeName + "
");
}
y=y.nextSibling;
}

* Node Properties
In the XML DOM, each node is an object.
Objects have methods and properties, that can be accessed and manipulated by JavaScript.
Three important node properties are:    * nodeName
* nodeValue
* nodeType
The nodeName property specifies the name of a node.

* nodeName of an element node is the same as the tag name
* nodeName of an attribute node is the attribute name
* nodeName of a text node is always #text
* nodeName of the document node is always #document
The nodeValue property specifies the value of a node.
* nodeValue for element nodes is undefined
* nodeValue for text nodes is the text itself
* nodeValue for attribute nodes is the attribute value

The following code retrieves the text node value of the first element:

x=xmlDoc.getElementsByTagName("title")[0].childNodes[0];
txt=x.nodeValue;
x.nodeValue="Easy Cooking";

The nodeType property specifies the type of node.
The most important node types are:
Node type     NodeType
Element              1
Attribute            2
Text                   3
Comment          8
Document        9

x=xmlDoc.getElementsByTagName('title').length;
//the x variable will hold a node list
x=xmlDoc.getElementsByTagName('title');
for (i=0;i
{
document.write(x[i].childNodes[0].nodeValue);
document.write("
");
}
The attributes property of an element node returns a list of attribute nodes.
This is called a named node map, and is similar to a node list, except for some differences in methods and properties.
A attribute list keeps itself up-to-date. If an attribute is deleted or added, the list is automatically updated.
x=xmlDoc.getElementsByTagName('book')[0].attributes;
document.write(x.getNamedItem("category").nodeValue);
document.write("
" + x.length);

The example below loops through all child nodes of , and displays their names and values:

All modern browsers support the W3C DOM specification.
However, there are some differences between browsers. One important difference is:
* The way they handle white-spaces and new lines
Internet Explorer will NOT treat empty white-spaces, or new lines as text nodes, wile other browsers will.
x=xmlDoc.documentElement.childNodes;
document.write("Number of child nodes: " + x.length);

DOM - Parent NodeAll nodes has exactly one parent node. The following code navigates to the parent node of :
x=xmlDoc.getElementsByTagName("book")[0];
document.write(x.parentNode.nodeName);

Firefox, and some other browsers, will treat empty white-spaces or new lines as text nodes, Internet Explorer will not.
This causes a problem when using the properties: firstChild, lastChild, nextSibling, previousSibling.
To avoid navigating to empty text nodes (spaces and new-line characters between element nodes), we use a function that checks the node type:

function get_nextSibling(n)
{
y=n.nextSibling;
while (y.nodeType!=1)
{
y=y.nextSibling;
}
return y;
}
The nodeValue property is used to get the text value of a node.
The getAttribute() method returns the value of an attribute.

Get the Value of an Element
In the DOM, everything is a node. Element nodes does not have a text value.
The text of an element node is stored in a child node. This node is called a text node.
The way to get the text of an element, is to get the value of the child node (text node).
Get an Element Value
The getElementsByTagName() method returns a node list containing all elements with the specified tag name
in the same order as they appear in the source document.
x=xmlDoc.getElementsByTagName("title")[0];
The childNodes property returns a list of child nodes. The element has only one child node. It is a text node.
The following code retrieves the text node of the element:
x=xmlDoc.getElementsByTagName("title")[0];
y=x.childNodes[0];
The nodeValue property returns the text value of the text node:
x=xmlDoc.getElementsByTagName("title")[0];
y=x.childNodes[0];
txt=y.nodeValue;

Get the Value of an Attribute

In the DOM, attributes are nodes. Unlike element nodes, attribute nodes have text values.
The way to get the value of an attribute, is to get its text value.
This can be done using the getAttribute() method or using the nodeValue property of the attribute node.
Get an Attribute Value - getAttribute()
The getAttribute() method returns an attribute value.
The following code retrieves the text value of the "lang" attribute of the first element:
txt=xmlDoc.getElementsByTagName("title")[0].getAttribute("lang");
Get an Attribute Value - getAttributeNode()
The getAttributeNode() method returns an attribute node.
The following code retrieves the text value of the "lang" attribute of the first element:
x=xmlDoc.getElementsByTagName("title")[0].getAttributeNode("lang");
txt=x.nodeValue;

Change the Value of an Element

In the DOM, everything is a node. Element nodes do not have a text value.
The text of an element node is stored in a child node. This node is called a text node.
The way to change the text of an element, is to change the value of the child node (text node).
Change the Value of a Text Node
The nodeValue property can be used to change the value of a text node.
The following code changes the text node value of the first element:
x=xmlDoc.getElementsByTagName("title")[0].childNodes[0];
x.nodeValue="Easy Cooking";
Change the Value of an Attribute
In the DOM, attributes are nodes. Unlike element nodes, attribute nodes have text values.
The way to change the value of an attribute, is to change its text value.
This can be done using the setAttribute() method or using the nodeValue property of the attribute node.
Change an Attribute Using setAttribute()
The setAttribute() method changes the value of an existing attribute, or creates a new attribute.
The following code changes the category attribute of the element: