var HTML = "";
var space = "";
var blank = "";
function getSubject()
{
var xmlDoc;
if(window.ActiveXObject)
{
//解决JavaScript请求跨域的问题
var xml = new ActiveXObject("Microsoft.XMLHTTP");
var xmlurl = appPath+'/standardocs/nav_getStandarXml.do';
//xml.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xml.open("post",xmlurl,false);
xml.send(null);
//debugger;
//获得操作的xml文件的对象
xmlDoc = new ActiveXObject('Microsoft.XMLDOM');
xmlDoc.async = false;
//xmlDoc.setProperty("SerpoverHTTPRequest", true);
//alert("ShareFileUrl:"+ShareFileUrl+"menu_XML.xml");
xmlDoc.load(xml.responseXML);
if(xmlDoc == null)
{
alert('您的浏览器不支持xml文件读取,于是本页面禁止您的操作,推荐使用IE5.0以上可以解决此问题!');
window.location.href='/index.do';
return;
}
//解析xml文件,判断是否出错
if(xmlDoc.parseError.errorCode != 0)
{
alert(xmlDoc.parseError.reason);
return;
}
//获得根接点
var nodes = xmlDoc.documentElement.childNodes;
//得到根接点下共有子接点个数,并循环
HTML="<table width=100% border=0 cellpadding=0 cellspacing=0 style='font-size:12px'>";
for(var i=0; i<nodes.length; i++)
{
//如果接点名为 tree
if(nodes(i).nodeName == "tree")
{
readTree(nodes(i));
}
//如果接点名为 node
else if(nodes(i).nodeName == "node")
{
readNode(nodes(i));
}
}
HTML += "</table>";
//删除对象
delete(xmlDoc);
//显示HTML
var mainShow = document.getElementById("show");
mainShow.innerHTML = HTML;
return;
}
else if (document.implementation && document.implementation.createDocument)
{
xmlDoc=document.implementation.createDocument("","",null);
xmlDoc.async = false;
//alert("ShareFileUrl:"+ShareFileUrl);
xmlDoc.load("menu_XML.xml");
if (xmlDoc.documentElement.tagName != "parsererror") {
//获得根接点
var nodes = xmlDoc.documentElement.childNodes;
//得到根接点下共有子接点个数,并循环
HTML="<table width=100% border=0 cellpadding=0 cellspacing=0 style='font-size:12px'>";
for(var i=0; i<nodes.length; i++)
{
//如果接点名为 tree
//alert(nodes[i].nodeName);
if(nodes[i].nodeName == "tree")
{
readTree_firefox(nodes[i]);
}
//如果接点名为 node
else if(nodes[i].nodeName == "node")
{
readNode_firefox(nodes[i]);
}
}
HTML += "</table>";
//删除对象
delete(xmlDoc);
//显示HTML
var showDiv = document.getElementById("show");
showDiv.innerHTML = HTML;
return;
} else
{
alert("An Error Occurred");
}
}
else
{
alert('您的浏览器不支持该脚本!');
}
}
//读Tree节点
function readTree(cI)
{
var nodes = cI.childNodes;
var menuHTML = space;
var pdf_link = "standardPDF";
HTML += "<tr><td height=24";
if(cI.getAttribute("lv") == "1")
{
HTML += " bgcolor=#c8d6f1";
}else if(cI.getAttribute("lv") == "2")
{
HTML += " bgcolor=#dfe8f7";
}
//点击菜单事件,调用divshow(vid)函数
HTML += " onclick=javascript:divshow('"+cI.getAttribute("id")+"');";
HTML += " style='cursor:pointer'> ";
for(var j=0; j< cI.getAttribute("lv")-1; j++) {HTML += " "; }
menuHTML += blank;
//得到超级链接
//如果该节点的连接属性不为空,则连接
if(cI.selectNodes("link")(0).text != "")
{
menuHTML += "<a href='" +ShareFileUrl+ pdf_link + "/";
menuHTML += cI.selectNodes("link")(0).text;
menuHTML += "'";
//目标
if(cI.selectNodes("target")(0).text != "")
{
menuHTML += " target='" + cI.selectNodes("target")(0).text;
menuHTML += "'";
}
//点击菜单事件,调用divshow(vid)函数
//menuHTML += " onclick=javascript:divshow('"+cI.getAttribute("id")+"');";
//得到节点标题
menuHTML += " title='";
menuHTML += cI.selectNodes("title")(0).text;
//结束
menuHTML += "'>";
}
//否则为空链接
else
{
//menuHTML += "#";
}
//得到节点的正文
menuHTML += cI.selectNodes("text")(0).text;
if(cI.selectNodes("link")(0).text != "")
{
menuHTML += "</a>";
}
//将menuHTML设置添加到HTML字符串
HTML += menuHTML;
HTML += "</td></tr>";
//得到该节点的属性值<span
HTML += "<tr><td>";
HTML += "<div id='"+cI.getAttribute("id")+"' ";
if(cI.getAttribute("lv") != "1" && cI.getAttribute("lv") == "2")
{
HTML += " style='display:none'";
}
HTML += ">/n";
HTML += "<table width=100% border=0 cellpadding=0 cellspacing=0 style='font-size:12px'>";
for(var i=0; i<nodes.length; i++)
{
var tempImg = "";
tempImg += blank;
if(nodes(i).nodeName == "tree")
{
space += tempImg;
readTree(nodes(i));
space = "";
}
else if(nodes(i).nodeName == "node")
{
space += tempImg;
readNode(nodes(i));
}
}
HTML += "</table></div></td></tr>/n";
return;
}
//读Node节点
function readNode(cI)
{
var nodeHTML = space;
nodeHTML += blank;
//设置超级链接
nodeHTML += "<a href='";
//得到连接地址
nodeHTML += cI.selectNodes("link")(0).text;
//目标
if(cI.selectNodes("target")(0).text != "")
nodeHTML += "' target='"+cI.selectNodes("target")(0).text;
//得到节点标题
nodeHTML += "' title='";
nodeHTML += cI.selectNodes("title")(0).text;
//结束
nodeHTML += "'>";
//得到节点的正文
nodeHTML += cI.selectNodes("text")(0).text;
nodeHTML += "</a><br>/n";
HTML += nodeHTML;
//HTML += "<div id='"+cI.getAttribute("id")+"'>";
space = "";
return;
}
//读Tree节点
function readTree_firefox(cI)
{
var nodes = cI.childNodes;
var menuHTML = space;
var pdf_link = "standardPDF";
HTML += "<tr><td height=24";
if(cI.getAttribute("lv") == "1")
{
HTML += " bgcolor=#c8d6f1";
}else if(cI.getAttribute("lv") == "2")
{
HTML += " bgcolor=#dfe8f7";
}
//点击菜单事件,调用divshow(vid)函数
HTML += " onclick=javascript:divshow('"+cI.getAttribute("id")+"');";
HTML += " style='cursor:pointer'> ";
for(var j=0; j< cI.getAttribute("lv")-1; j++) {HTML += " "; }
menuHTML += blank;
//得到超级链接
//如果该节点的连接属性不为空,则连接
var cI_text = cI.getElementsByTagName("text")[0].textContent;
var cI_target = cI.getElementsByTagName("target")[0].textContent;
var cI_title = cI.getElementsByTagName("title")[0].textContent;
var cI_link = cI.getElementsByTagName("link")[0].textContent;
if(cI_link != "")
{
menuHTML += "<a href='" +ShareFileUrl+ pdf_link + "/";
menuHTML += cI_link;
menuHTML += "'";
//目标
if(cI_target != "")
{
menuHTML += " target='" + cI_target;
menuHTML += "'";
}
//点击菜单事件,调用divshow(vid)函数
//menuHTML += " onclick=javascript:divshow('"+cI.getAttribute("id")+"');";
//得到节点标题
menuHTML += " title='";
menuHTML += cI_title;
//结束
menuHTML += "'>";
}
//否则为空链接
else
{
//menuHTML += "#";
}
//得到节点的正文
menuHTML += cI_text;
if(cI_link != "")
{
menuHTML += "</a>";
}
//将menuHTML设置添加到HTML字符串
HTML += menuHTML;
HTML += "</td></tr>";
//得到该节点的属性值<span
HTML += "<tr><td>";
HTML += "<div id='"+cI.getAttribute("id")+"' ";
if(cI.getAttribute("lv") != "1" && cI.getAttribute("lv") == "2")
{
HTML += " style='display:none'";
}
HTML += ">/n";
HTML += "<table width=100% border=0 cellpadding=1 cellspacing=0 style='font-size:12px'>";
for(var i=0; i<nodes.length; i++)
{
var tempImg = "";
tempImg += blank;
if(nodes[i].nodeName == "tree")
{
space += tempImg;
readTree_firefox(nodes[i]);
space = "";
}
else if(nodes[i].nodeName == "node")
{
space += tempImg;
readNode_firefox(nodes[i]);
}
}
HTML += "</table></div></td></tr>/n";
return;
}
//读Node节点
function readNode_firefox(cI)
{
var nodeHTML = space;
nodeHTML += blank;
//设置超级链接
/* nodeHTML += "<a href='";
//得到连接地址
nodeHTML += cI.selectNodes("link")(0).text;
//目标
if(cI.selectNodes("target")(0).text != "")
nodeHTML += "' target='"+cI.selectNodes("target")(0).text;
//得到节点标题
nodeHTML += "' title='";
nodeHTML += cI.selectNodes("title")(0).text;
//结束
nodeHTML += "'>";
//得到节点的正文
nodeHTML += cI.selectNodes("text")(0).text;
nodeHTML += "</a><br>/n";
HTML += nodeHTML;
//HTML += "<div id='"+cI.getAttribute("id")+"'>";
space = "";
*/
return;
}
//操作对象的显示还是隐藏效果
function divshow(vid)
{
var divObj = document.getElementById(vid);
if(divObj.style.display == "none")
{
divObj.style.display = "block";
}
else
{
divObj.style.display = "none";
}
return;
}
后台取得标准文档字符串代码
public void getStandarXml() throws Exception{
try{
response.setContentType("text/xml;charset=UTF-8");//让response以xml的形式进行请求
StandarXml standarxml = standarDocsManager.getStandarXML();
BufferedWriter wd = new BufferedWriter(new OutputStreamWriter(response.getOutputStream(), HTTP.UTF_8));
wd.write(standarxml.getStandarxml());//将xml写到前台
wd.flush();
}catch(Exception e){
e.printStackTrace();
}
}