// f should be all the XML text taken from innerHTML
{
var remtext=f
var el_text=""
var tagstack=0
var stylesheet=getXstyle(f)
//alert(stylesheet)
//document.write("
")
//loop through the tags, exclude
for(var i=0;i<=e.length-2;i++)
{
el_text=(trimText(getText(e[i],e[i+1],remtext))); //the text between the tags
remtext=remtext.substring(remtext.indexOf(e[i+1])); //advance the text
if (gettagtype(e[i])==0 && e[i].charAt(0)!="X") //ignore or wrapper
{tagstack++} //add to stack if opening tag
else if(gettagtype(e[i])==1 && e[i].substring(0,2)!="/X")
{tagstack--} //take off stack if closing tag
if(e[i].charAt(0)!="X")
{
if(gettagtype(e[i])==0)
{
makeFlowobject(e[i],el_text,stylesheet);
}
else if(tagstack==0 && gettagtype(e[i])==1 && e[i].substring(0,2)!="/X") //exclude special tags
{
makeFlowobject(e[i],el_text,stylesheet);
}
else if(tagstack >0 && gettagtype(e[i])==1 && e[i].substring(0,2)!="/X") //print the text
{
//var this
makeFlowobject(e[i],el_text,stylesheet);
document.write(el_text);
}
}
}
alert(htmstring)
}
////////////////////////////
//end function printarray//
///////////////////////////
function gettagtype(e)
//cannot at present identify empty tag as in text / is not returned.
//Will need another routine to do this, probably identify from innerHTML
//opening tag=0,closing tag=1,emptytag=2,comment=3
{
var tagtype=0
if (e.charAt(0)=="/")
{tagtype=1}
else if (e.charAt(0)=="!")
{tagtype=3}
else tagtype=0
return tagtype
}
////////////////////////////
//end function gettagtype//
///////////////////////////
/*-------------------------------------------------BEGIN REMOVED
function areTagsSameType(e,f)
//e is present tag,f is next tag
{
var sametype=true
if(f.substring(1)==e)
{sametype=true}
else sametype=false
//return true or false
return sametype
}
////////////////////////////////
//end function areTagsSameType//
////////////////////////////////
-------------------------------------------------END REMOVED*/
function getText(e,f,g)
//e is present tag,f is next tag,g is the remnant text
//returns the text between two tags
{
var Uppertext=g.toUpperCase()
var endindex=Uppertext.indexOf(f,e.length)
var el_text=g.substring(e.length+1,endindex-1)
return el_text
}
////////////////////////
//end function getText//
////////////////////////
function trimText(e)
//e is text to trim
//removes all text to the left of > and returns the edited string
{
var textstr=e;
var startnum=e.indexOf(">",0);
textstr=e.substring(startnum+1);
return textstr;
}
/////////////////////////
//end function trimText//
/////////////////////////
//--------------------------------------------BEGIN REMOVED
/*
function getStylingtag(e,f)
// e is opening tag,f is closing tag.
//adds the appropiate style to the text and prints it.
//check to see what type the closing tag is, if it is the same type then return the opening tag
//if it is another opening tag then just apply the style.
//if it is a different tag and a closing tag, apply the style of the closing tag
{
if(areTagsSameType(e,f)==true)
{return e;}
else if(gettagtype(f)==0)
{return e;}
else {return f.substring(1);}
}
//////////////////////////////
//end function getStylingtag//
/////////////////////////////
//--------------------------------------------END REMOVED*/
function makeFlowobject(e,f,g)
//Get type of tag if opening styleit ,if closing close it with appropiate DIV or SPAN
//Will need to link with style sheet of
TYPE
//e is the tag, f the text to style, g the style sheet
{
//htmstring=htmstring+"A"
//alert(htmstring)
e=e.toLowerCase(); //IE4 DOM represents all tags in upper case.
if(gettagtype(e)==0)
{
if (g.indexOf(e,0)!=-1)
{
var ss=getStyleString(e,g);
//alert(ss)
if(ss.indexOf("display:block",0)!=-1)
{
document.write(""+f)
htmstring=htmstring+"
"+f
}
else
{
document.write("
"+f)
htmstring=htmstring+""+f
}
}
else if(e=="greeting")
{
document.write(""+f)
//alert("
"+f)
}
else if(e=="insult")
{
document.write("
"+f)
//alert("
"+f)
}
else if (e=="emphasis")
{
document.write(""+f)
//alert(""+f)
}
else {
document.write(""+f)
htmstring=htmstring+""+f
//alert(""+"S"+f)
}
}
else if(gettagtype(e)==1)
{
e=e.substring(1)
//alert(e)
if (g.indexOf(e,0)!=-1)
{
var ss=getStyleString(e,g);
if(ss.indexOf("display:block",0)!=-1)
{
document.write("
")
htmstring=htmstring+"
"
}
else
{
document.write("")
htmstring=htmstring+""
}
}
else if(e=="greeting")
{
document.write("
")
//alert(e+"
")
}
else if(e=="insult")
{
document.write("")
//alert(e+"
")
}
else if(e=="emphasis")
{
document.write("")
//alert(e+"
")
}
else {
document.write("")
htmstring=htmstring+""
//alert(e+"
")
}
}
//
}
///////////////////////////////
//end function makeFlowobject//
///////////////////////////////
function getXstyle(e)
//gets the style sheet in innerHTMLand returns it as a string
//e should =innerHTML
{
var beginnum=e.indexOf("XSTYLE",0);
//alert(beginnum)
var endnum=e.indexOf("/XSTYLE",0);
//alert(endnum)
var stylesheet= e.substring(beginnum+7,endnum-1);
//alert(stylesheet)
return stylesheet
}
//////////////////////////
//end function getXstyle//
//////////////////////////
function getStyleString(e,f)
//e is the tag in lowercase, f the style string
//returns the style string of the requested tag
{
var beginnum=f.indexOf(e,0)+e.length;
var remstring=f.substring(beginnum);
var endnum=remstring.indexOf("}",0);
var stylestring=remstring.substring(1,endnum);
//alert (stylestring);
return stylestring;
}
///////////////////////////////
//end function getStyleString//
///////////////////////////////
function displayHtml(e)
{
return
}
//------------------------------------------------------
/*
//-------------------------------------------------------------------------
//Note cannot use empty tags with this very primative first coding.Document must be well formed
//Need to add code to check for well formed ness before running.
//(Quick and dirty check,tagstack should =0 at end)
//sample XML document
//
//
//
// document{font-size:8pt;color:green;}
// greeting{
// color:red;
// font-size:18pt;
// display:block;
// }
// insult{
// color:teal;
// font-size:28pt;
// display:block;
// }
// emphasis{
// color:black;
// font-size:38pt;
// display:inline;
// }
//
//
//
// Hello world
// Hello XMLDOC tag
// Hiss off you stupidstupid old fool!!
//
//
//
//
//
//*/