关于 XML 和 javascript 在 asp.net页面显示 tree 的问题
因为是 vs2003 , 也没有下载 treeview 控件
大体代码 是这样的: 调用webserivce 引用了一段 xml报文 改写报文格式
用javascript的方式 展现出来
可 最后出了点问题~~~
CS代码:
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
InterManager.InterManagerService IM = new SmsOneSelf.InterManager.InterManagerService();
string usersxml = IM.getOrgArch();
IM.Dispose();
XmlDocument dom = new XmlDocument();
XmlDocument newdom = new XmlDocument();
dom.LoadXml(usersxml);
//XmlNodeList nodes =dom.GetElementsByTagName( "orgUnit ");
XmlNodeList orgList = dom.SelectSingleNode( "organization ").ChildNodes;
XmlElement newroot = newdom.CreateElement( "tree ");
newroot.SetAttribute( "text ", "root ");
foreach(XmlNode xnode in orgList)
{
XmlElement xe=(XmlElement)xnode;
string str = xe.GetAttribute( "upid ")==null? " ":xe.GetAttribute( "upid ");
if(str== "0 "||str== "-1 "||str== " ")
{
XmlElement neworg = newdom.CreateElement( "tree ");
neworg.SetAttribute( "id ",xe.GetAttribute( "id "));
neworg.SetAttribute( "text ",xe.GetAttribute( "name "));
neworg.SetAttribute( "target ", " ");
neworg.SetAttribute( "action ", " ");
neworg = buileXmlTree(neworg,orgList,newdom);
newroot.AppendChild(neworg);
}
}
//Response.ContentType= "text/xml ";
//Response.Write(newroot.ToString());
//XmlWriter xw = new XmlWriter();
//Response.Write(newroot.Value);
//XmlTextWriter xtw = new XmlTextWriter(newroot.ToString());
//Console.Write(newroot.ToString());
//xtw.Flush();
//xtw.Close();
//newdom.Save(Console.Out);
// 主要就是这个地方 想输出流 却总是输出不对 尝试了很多方法
Console.Write(newroot.ToString());
}
public XmlElement buileXmlTree(XmlElement root,XmlNodeList nodes,XmlDocument dom)
{
foreach(XmlNode node in nodes)
{
XmlElement xe = (XmlElement) node;
if(xe.GetAttribute( "upid ")==root.GetAttribute( "id "))
{
XmlElement child = dom.CreateElement( "tree ");
child.SetAttribute( "id ",xe.GetAttribute( "id "));
child.SetAttribute( "text ",xe.GetAttribute( "name "));
child.SetAttribute( "target ", " ");
c