"Martin Honnen" said
pr***********@gmail.com wrote: I know one way of doing it by document.getElementById().innerHTML, but
that will work only when you gave id to all the text in the file.
implementing a serialization with script itself
is possible of course as the DOM tree is there.
Such as:
function gettext( o ) {
o = o || document.body;
var b, s = '', j = o && o.firstChild, phrase =
/^(abbr|b|big|cite|code|em|font|i|kbd|span|s|samp|s mall|strong|tt|u)$/i;
if( j && o.childNodes.length<500 ) {
for ( ; j !== null; j = j.nextSibling ) {
if( j.nodeType === 3 ) {
s += j.nodeValue || '';
}
else if( j.nodeType === 1 ) {
b = phrase.test( j.tagName ) ? '' : ' ';
s += b + gettext( j ) + b;
}
}
}
return s.replace( /\s+/, ' ' );
}
Other approaches are certainly more efficient, but this is perhaps still
readable. More about nodetypes for example here:
<URL:
http://msdn.microsoft.com/workshop/a...erties/nodetyp
e.asp > (watch for wrap)
Some effort is made to keep space characters around some phrase elements
with the rather voluminous regex in variable "phrase". It 's not the most
elegant part of the script, but prevents words running together.
hth
ivo
http://4umi.com/web/javascript/