日期:2014-05-16  浏览次数:20457 次

DOM中关于LoadXML的问题
var   strXML   =   ' <%=Session[ "g_MenuXML "].ToString()%> ';
               
                var   xmlDoc;
                if(   window.ActiveXObject   )   {
                        xmlDoc   =   new   ActiveXObject   (   "Msxml2.DOMDocument "   );
                        xmlDoc.loadXML   (   strXML   );
                }
                else   if(   window.XMLHttpRequest   )   {
                        xmlDoc   =   (new   DOMParser()).parseFromString(strXML, 'text/xml ');
                }
                alert(xmlDoc.firstChild);
                var   menuItems   =   xmlDoc.getElementsByTagName( "menuItem ");
                alert(   menuItems.length);
             
弹出的对话框firstChild总是null,length总是0,我怀疑是我strXML格式的问题,strXML的内容是:


<?xml   version= "1.0 "   encoding= "utf-8 "?> <Menu> <Department   DepartmentId= "4 "   DepartmentName= "产品销售部 "> <menuItem   iconFile= "\images\1.ico "   menuType= "mainMenu "   menuId= "1 "   menuName= "我是主菜单1 "> <menuItem   menuType= "subMenu "   menuId= "1 "   menuName= "俺是子菜单1 "> <menuItem   menuType= "operatorMenu "   menuId= "1 "   menuName= "咱是操作菜单1 "   /> </menuItem> </menuItem> <menuItem   icon= "\images\1.ico "   menuType= "mainMenu "   menuId= "10 "   menuName= "我是主菜单10 "> <menuItem   menuType= "subMenu "   menuId= "11 "   menuName= "俺是子菜单10 "> <menuItem   menuType= "operatorMenu "   menuId= "10 "   menuName= "咱是操作菜单10 "   /> </menuItem> </menuItem> <menuItem   icon= "1.ico "   menuType= "mainMenu "   menuId= "13 "   menuName= "我是主菜单13 "> <menuItem   menuType= "subMenu "   menuId= "14 "   menuName= "俺是子菜单13 "> <menuItem   menuType= "operatorMenu "   menuId= "13 "   menuName= "咱是操作菜单13 "   /> </menuItem> </menuItem> </Department> </Menu>

我觉得没什么问题啊!各个结点之间没有任何符号,对不?

------解决方案--------------------
"\ "字符要转义
"\\ "
var strXML= ' <?xml version= "1.0 " encoding= "utf-8 "?> <Menu> <Department DepartmentId= "4 " DepartmentName= "产品销售部 "> <menuItem iconFile= "\\images\\1.ico " menuType= "mainMenu " menuId= "1 " menuName= "我是主菜单1 "> <menuItem menuType= "subMenu " menuId= "1 " menuName= "俺是子菜单1 "> <menu