我想用javascript + xsl+XML无法解释XML,郁闷中。生成XML的代码如下
string temp="<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Prices>\n";
temp +="<Metal Name=\"cu\" Prompt=\"3M\"";
temp +=" Price=\"32\" Lots=\"3\" Depth=\"1\" Vol=\"3\" >\n";
temp +="<Bids>\n";
temp +="<Bid Name=\"CU\" Broker_Code=\"CA\" Prompt=\"2007-06-23\" Broker_Prompt=\"3M\"  Price=\"1\" Lots=\"1\" Depth=\"1\"  brokerno=\"3\"/>";
temp +="</Bids>\n<Offers>\n";
temp +="<Offer Name=\"CU\" Broker_Code=\"CA\" Prompt=\"2007-06-23\" Broker_Prompt=\"3M\"  Price=\"3\" Lots=\"1\" Depth=\"2\" brokerno=\"3\"/>";
temp +="</Offers>\n</Metal>\n";
temp+= "</Prices>\n";
Response.AddHeader("ContentType", "text/xml");
Response.Write(temp);
Response.End();解释XML的JAVASCRIPT程序如下。
   function aa()
{  
XmlHttp   =   new   ActiveXObject("Microsoft.XMLHTTP");   
XmlHttp.open("POST","online_select.aspx",false,null,null);
 XmlHttp.send();
var xmldoc, xsldoc;
xmldoc = new ActiveXObject("Msxml2.DOMDocument");
xsldoc = new ActiveXObject("Msxml2.DOMDocument");
xmldoc.async = false;
xsldoc.async = false;
xmldoc.load(XmlHttp.responseXML);
xsldoc.load("select_price_main.xsl");
bodyStr = xmldoc.transformNode(xsldoc) 
trade_veiw.innerHTML=bodyStr;
alert(bodyStr);
}
超级郁闷没法显示。如果将生成XML的ASP。NET换成XML就正常显示。郁闷。XML文件如下。
<?xml version='1.0' encoding='UTF-8'?>
<?xml-stylesheet type='text/xsl' href='select_price_main.xsl' ?>
<Prices>
<Metal Name='CU' Prompt='3M'  Price='6700' Lots='3' Depth='1' Vol='3'>
<Bids>
<Bid Name='CU' Broker_Code='CA' Prompt='2007-06-23' Broker_Prompt='3M'  Price='1' Lots='1' Depth='1'  brokerno='3'/>
 </Bids>
<Offers>
<Offer Name='CU' Broker_Code='CA' Prompt='2007-06-23' Broker_Prompt='3M'  Price='3' Lots='1' Depth='2' brokerno='3'/>
 </Offers>
</Metal>
</Prices>

解决方案 »

  1.   

    Response.Clear();
    string temp="<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Prices>\n";
    temp +="<Metal Name=\"cu\" Prompt=\"3M\"";
    temp +=" Price=\"32\" Lots=\"3\" Depth=\"1\" Vol=\"3\" >\n";
    temp +="<Bids>\n";
    temp +="<Bid Name=\"CU\" Broker_Code=\"CA\" Prompt=\"2007-06-23\" Broker_Prompt=\"3M\"  Price=\"1\" Lots=\"1\" Depth=\"1\"  brokerno=\"3\"/>";
    temp +="</Bids>\n<Offers>\n";
    temp +="<Offer Name=\"CU\" Broker_Code=\"CA\" Prompt=\"2007-06-23\" Broker_Prompt=\"3M\"  Price=\"3\" Lots=\"1\" Depth=\"2\" brokerno=\"3\"/>";
    temp +="</Offers>\n</Metal>\n";
    temp+= "</Prices>\n";
    Response.AddHeader("ContentType", "text/xml");
    Response.Write(temp);
    Response.End();
      

  2.   

    XmlHttp   =   new   ActiveXObject("Microsoft.XMLHTTP");   
    XmlHttp.open("POST","online_select.aspx",false,null,null);
     XmlHttp.send();
    alert(XmlHttp.responseText)
    看看是否是xml格式的
      

  3.   

    var xmldoc, xsldoc;
    xmldoc = new ActiveXObject("Msxml2.DOMDocument");
    xsldoc = new ActiveXObject("Msxml2.DOMDocument");
    xmldoc.async = false;
    xsldoc.async = false;
    xmldoc.load("default.aspx")
     
    xsldoc.load("select_price_main.xsl");bodyStr =xmldoc.transformNode(xsldoc.documentElement)
    alert(bodyStr);
    trade_veiw.innerHTML=bodyStr;
      

  4.   

    xmldoc.load("default.aspx")
    换成你的文件名
      

  5.   

    原来的错误是因为xmldoc.load(XmlHttp.responseText);应该是xmldoc.loadXML(XmlHttp.responseText);
      

  6.   

    孟老大,我按你的方法还是不行,显示来的结果为
    <?xml version="1.0" encoding="UTF-16"?><div id="divPrices" style="overflow:auto; height:100%; width:100%" class="ScrollBars" xmlns:fo="http://www.w3.org/1999/XSL/Format"></div>
      

  7.   

    终于可以显示了,为什么用
    xmldoc.load(XmlHttp.responseXML);
    非常感谢各位的帮忙.
      

  8.   

    load是load文件
    loadXml是xml的string内容