请教,谢谢,xml+vml问题,

[img]http://img9.wal8.com/img9/121886_20110104174100/s/12941341369845_640_640.jpg[/img]
我这是通过VML+XML生成的一个组织架构图,现在是想把每个助理都画在(如董事长助理,则从画在董事长的右边....)可以改变XML的结构,只要能实现,就行,谢谢.在附件有代码,那位大哥大姐有空帮看下,

可以改,我先看看,你等等。改好了我怎么发给你?

[code="java"]


v\:*{ behavior:url(#default#VML); } v\:RoundRect{ text-align:center; position:relative; } v\:TextBox{ vertical-align:middle; font-size:13px; } function $(id){ return document.getElementById(id); } function Point2D(x,y){ this.x = x; this.y = y; } function Xml2Vml(xmlFile){ this.XML = new ActiveXObject("MSXML2.DOMDocument.5.0"); this.XML.async=false; this.XML.load(xmlFile); this.SpanX = 10; this.SpanY = 25; this.ItemWidth = 120; this.ItemHeight = 25; this.assistSpanX = 40; this.VmlRoot = document.createElement('<v:group coordsize="1000,1000" id="vml" style="width:1000px;height:1000px;">'); } Xml2Vml.prototype.RecursiveParse = function(rootNode,offset){ var allChild = rootNode.childNodes; var xOffset = offset.x; var yOffset = offset.y; var zl=rootNode.getAttribute("value"); if(allChild.length==0){ rootNode.setAttribute("LeftX",xOffset); rootNode.setAttribute("RightX",xOffset+this.ItemWidth); xOffset += this.SpanX + this.ItemWidth; }else{ for(var i=0;i<allChild.length;i++){ var x=xOffset; var y=yOffset+2*this.SpanY+this.ItemHeight; var w = this.RecursiveParse(allChild[i],new Point2D(x,y)); xOffset += this.SpanX + w; } rootNode.setAttribute("LeftX",(parseInt(allChild[0].getAttribute("LeftX")) + parseInt(allChild[0].getAttribute("RightX")))/2); rootNode.setAttribute("RightX",(parseInt(allChild[allChild.length-1].getAttribute("LeftX")) + parseInt(allChild[allChild.length-1].getAttribute("RightX")))/2); } rootNode.setAttribute("PosY",yOffset); return xOffset-offset.x-this.SpanX; } Xml2Vml.prototype.ParseXml = function(){ this.RecursiveParse(this.XML.documentElement,new Point2D(0,0)); } Xml2Vml.prototype.RecursiveRender = function(xmlNode){ var allChild = xmlNode.childNodes; var xl = xmlNode.getAttribute("LeftX"); var xr = xmlNode.getAttribute("RightX"); var x = (parseInt(xl)+parseInt(xr))/2; var y = xmlNode.getAttribute("PosY"); var str = xmlNode.tagName; //增加一个判断是否为助理的属性 var type= xmlNode.getAttribute("type"); if(type=="assist"){ //如果是助理的话,特殊处理一下 xl = xmlNode.parentNode.getAttribute("LeftX"); xr = xmlNode.parentNode.getAttribute("RightX"); x = (parseInt(xr)+parseInt(xl))/2+this.ItemWidth+this.assistSpanX; xright = parseInt(xr)+parseInt(this.assistSpanX); y = xmlNode.parentNode.getAttribute("PosY"); var str = xmlNode.tagName; if(xmlNode!=this.XML.documentElement) this.VmlRoot.appendChild(document.createElement('<v:line from="'+(x-this.ItemWidth/2-this.assistSpanX)+','+(parseInt(y)+this.SpanY+this.ItemHeight/2)+'" to="'+(x-this.ItemWidth/2)+','+(parseInt(y)+this.SpanY+this.ItemHeight/2)+'" />')); y=parseInt(y)+this.SpanY; var RoundRect = document.createElement('<v:RoundRect style="width:'+this.ItemWidth+'px;height:'+this.ItemHeight+'px;left:'+(x-this.ItemWidth/2)+'px;top:'+y+'px" align="center">') RoundRect.appendChild(document.createElement('<v:shadow on="True" type="single" color="#b3b3b3" offset="5px,5px"/>')); var TextBox = document.createElement('<v:TextBox />'); TextBox.innerHTML = str; RoundRect.appendChild(TextBox); this.VmlRoot.appendChild(RoundRect); }else{ if(xmlNode!=this.XML.documentElement) this.VmlRoot.appendChild(document.createElement('<v:line from="'+x+','+y+'" to="'+x+','+(parseInt(y)+this.SpanY)+'" />')); y=parseInt(y)+this.SpanY; var RoundRect = document.createElement('<v:RoundRect style="width:'+this.ItemWidth+'px;height:'+this.ItemHeight+'px;left:'+(x-this.ItemWidth/2)+'px;top:'+y+'px" align="center">') RoundRect.appendChild(document.createElement('<v:shadow on="True" type="single" color="#b3b3b3" offset="5px,5px"/>')); var TextBox = document.createElement('<v:TextBox />'); TextBox.innerHTML = str; RoundRect.appendChild(TextBox); this.VmlRoot.appendChild(RoundRect); } if(allChild.length>0){ y += this.ItemHeight+this.SpanY; this.VmlRoot.appendChild(document.createElement('<v:line from="'+x+','+(y-this.SpanY)+'" to="'+x+','+y+'" />')); xl = (parseInt(allChild[0].getAttribute("LeftX")) + parseInt(allChild[0].getAttribute("RightX")))/2; xr = (parseInt(allChild[allChild.length-2].getAttribute("LeftX")) + parseInt(allChild[allChild.length-2].getAttribute("RightX")))/2; //这里从倒数第二个开始算 this.VmlRoot.appendChild(document.createElement('<v:line from="'+xl+','+y+'" to="'+xr+','+y+'" />')); for(var i=0;i<allChild.length;i++) this.RecursiveRender(allChild[i]); } } Xml2Vml.prototype.RenderVml = function(){ this.RecursiveRender(this.XML.documentElement); }



var Ins = new Xml2Vml("data.xml"); Ins.ParseXml(); Ins.RenderVml(); $("div").appendChild(Ins.VmlRoot);


[/code]

[code="java"]
<?xml version="1.0" encoding="GB2312"?>
<董事长>
<副董事长A>
<职员A1 />
<职员A1 />
<职员A2 />
<职员A3 />
<副董事长A助理 type="assist">
</副董事长A助理>
</副董事长A>

<副董事长B>
<职员B1 />
<职员B2 />
<职员B3 />
<副董事长B助理 type="assist">
</副董事长B助理>
</副董事长B>

<副董事长C>
<职员C1 />
<职员C2 />
<职员C3 />
<副董事长C助理 type="assist">
</副董事长C助理>
</副董事长C>
<董事长助理 type="assist">
</董事长助理>
</董事长>

[/code]

这个是结果你弄回去运行看看吧