Недавно до меня вдруг осенило

что при trace() вызывается метод toSring() объекта который трейсится.
Что захотелось в первую очередь, так это изменить отображение XML. Во первых, "разбор" XML когда он в одну строку неудобно, хочется видеть структуру.
(Звучит просто, но если постоянно просматривать при тестировании приходящие сообщения и когда приходится скролить вприва на десять экранов... )
Во вторых, при изменении прототипа Object трейсинг XML "ломается" и показывает полную чушь...
Ладно, короче, метод переписал, и пердоставляю его вашему вниманию. Кстати красивый на мой взгляд, тащусь я от рекурсии
Дам сразу с примером, чтобы было понятнее, можно вставить себе и потестить,

Код:
//Evgeniy Potapeno (aka john) john@3wgraphics.com http://www.3wgraphics.com
//This code is written for correct visual reflection of XML while testing (function trace).
//By default XML is shown in one line, and it would be nice to see its structure.
//By changing the method toString in the XML object, I have changed the reflection.
//I think it's not needed to explain the need of this solution.
//Below - a small example which reflects the changes.
//Let's create a simple XML and trace it in usual way.
text = "<a><b a='1' b='2' c='3'><c a='1' b='2' c='3'/>aaa<d a='1' b='2' c='3'/></b><c a='1' b='2' c='3'/><d a='1' b='2' c='3'/></a>"
anyXML = new XML(text)
trace(anyXML);
//In the output we see:
/*
<a><b a="1" b="2" c="3"><c a="1" b="2" c="3" />aaa<d a="1" b="2" c="3" /></b><c a="1" b="2" c="3" /><d a="1" b="2" c="3" /></a>
*/
//Now let's change the method toString and look for changes.
XML.prototype.__proto__.toString = function(tab)
{
var traced_value;
if(this.nodeType!=3)
{
if(this.nodeName!=null)
{
traced_value = "<"+this.nodeName;
for(var v in this.attributes)
{
traced_value+=" "+v+"=\""+this.attributes[v]+"\""
}
if(this.firstChild==null)
{
traced_value+=" />"
}else{
traced_value+=">\r\t"+tab+this.firstChild.toString(tab+"\t")+"\r"+tab+"</"+this.nodeName+">";
}
}else{
traced_value = this.firstChild.toString("");
}
}else{
traced_value=this.nodeValue;
}
if(this.nextSibling!=null)
{
traced_value+="\r"+tab+this.nextSibling.toString(tab);
}
return traced_value;
}
trace(" - - - - - new trace - - - - - - - - -");
trace(anyXML);
//In the output we see:
/*
<a>
<b a="1" b="2" c="3">
<c a="1" b="2" c="3" />
aaa
<d a="1" b="2" c="3" />
</b>
<c a="1" b="2" c="3" />
<d a="1" b="2" c="3" />
</a>
*/
//My congratulations.