把xml文件这样加载为什么不行啊

mgwms 2003-05-22 03:23:12
把xml文件这样加载<xml id=xmlData src="test.xml"></xml>为什么不行啊
这样是可以 的:
<xml id=xmlData >
<?xml version="1.0" encoding="gb2312"?>
<root>
<rows Product_Id="1" Product_Code="ISBN: 1-58861-075-6" CEPC_No="ISBN: 1-58861-075-6" Product_Name="AAPG Bulletin on CD1990-1999"/>
<rows Product_Id="2" Product_Name="AAPG Data_ROM 1993: More than 400,000 well records on a CD-ROM:"/>
<rows Product_Id="3" Product_Name="The Arabian Plate: Producing Fields and Other Undeveloped Hydrocarbon Discoveries (1991). (Digital Map)"/>
<rows Product_Id="4" Product_Code="1-58861-179-5" CEPC_No="1-58861-179-5" Product_Name="Petroleum Basins of South America"/>
<rows Product_Id="5" Product_Name="Bally Seismic Atlas Series:Seismic Expression of Structural Styles, Studies in Geology 15 (3 vols., 1 disc)"/>
<rows Product_Id="6" Product_Name="Combined Index on CD-ROM (2000 edition)."/>
<rows Product_Id="7" Product_Name="Gulf of Mexico Type Well File"/>
<rows Product_Id="8" Product_Name="International Developments in Exloratory Drilling(AAPG) 1950-1990"/>
</root>
</xml>
为什么???
...全文
691 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
tqinghaijn 2003-05-23
  • 打赏
  • 举报
回复
up
ssm1226 2003-05-22
  • 打赏
  • 举报
回复
有可能存在空格问题
mgwms 2003-05-22
  • 打赏
  • 举报
回复
encoding="gb2312" 编码的问题,气死我了 !
我一直都没有写错。我一直是拷贝那个正常执行的xml文件的编码。解决了,但是我还是不知道为什么错
谢谢 ssm1226(雨中人) !!结帐!
ssm1226 2003-05-22
  • 打赏
  • 举报
回复
IE中,test.xml文件可以浏览?
mgwms 2003-05-22
  • 打赏
  • 举报
回复
我把test.xml的文件改为:
<?xml version="1.0" encoding="gb2312"?>
<root>
<rows Product_Id="512" Product_Name="Immunology Today Online"/>
<rows Product_Id="513" Product_Name="EMBASE Alert CD"/>
<rows Product_Id="514" Product_Name="Ageline"/>
</root>

也不行!起了怪了。
mgwms 2003-05-22
  • 打赏
  • 举报
回复
alert为空!
ssm1226 2003-05-22
  • 打赏
  • 举报
回复
文件路径,文件有效性正确


就应该没什么问题,

try:

function init(){
oSel=document.all.sel;
xmldoc=xmlData.XMLDocument;
alert(xmldoc.xml)
if(xmldoc==null) return;
}
mgwms 2003-05-22
  • 打赏
  • 举报
回复
html:
<html>
<script language=javascript>
<!--
var xmldoc=null;
var oSel=null;

function toSearch(){
var oTxt=document.all.productname;
var strval=oTxt.value;
if(strval=="") return;
addOptions(strval);
}

function init(){
oSel=document.all.sel;
xmldoc=xmlData.XMLDocument;
if(xmldoc==null) return;
}

function getSearchNode(str){
var nodes=null;
xmldoc.setProperty("SelectionLanguage","XPath");
//nodes=xmldoc.selectNodes("//rows[translate(substring(@Product_Name,1,1),'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')='"+str.toLocaleLowerCase()+"']");
nodes=xmldoc.selectNodes("//rows[starts-with(translate(@Product_Name,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'),'"+str.toLocaleLowerCase()+"')]");
if(nodes.length<1) nodes=null;
return nodes;
}

function delOptions(){
while(oSel.length>0)
oSel.remove(0);
}

function addOptions(str){
var nodes=getSearchNode(str);
if(nodes==null) return;
delOptions();
for(var i=0;i<nodes.length;i++){
var node=nodes[i];
var oPts=new Option(node.getAttribute("Product_Name"),node.getAttribute("Product_Id"),true,false);
oSel.options[oSel.options.length]=oPts;
}
}
//-->
</script>

<body onload="javascript:init()">
<XML ID="xmlData" src="test.xml" async="false"></XML>
<select id="sel" name="sel">
<option value=0>选择...</option>
</select>
<br>
<textarea name=productname id=productname></textarea>
<br>
<input type=button value=search onclick=toSearch()>
</body>
</html>
mgwms 2003-05-22
  • 打赏
  • 举报
回复
test.xml:

<?xml version="1.0" encoding="gb2312"?>
<root>
<rows Product_Id="493" Product_Code="ENG2001" CEPC_No="ENG2001" Product_Name="Automotive Engines Database on CD-ROM(价格为非会员价)"/>
<rows Product_Id="494" Product_Code="ENG2001" CEPC_No="ENG2001" Product_Name="Automotive Engines Database on CD-ROM(价格为会员价)"/>
<rows Product_Id="495" Product_Code="UNS99.SET" CEPC_No="UNS99.SET" Product_Name="UNS 1999 Set(价格为会员价)"/>
<rows Product_Id="496" Product_Name="EMBASE CD"/>
<rows Product_Id="497" Product_Name="EMBASE CD"/>
<rows Product_Id="498" Product_Code="ENGD2001" CEPC_No="ENGD2001" Product_Name="2001 SAE Diesel Engines Collection on CD-ROM (价格为非会员价)"/>
<rows Product_Id="499" Product_Code="ENGD2001" CEPC_No="ENGD2001" Product_Name="2001 SAE Diesel Engines Collection on CD-ROM (价格为会员价)"/>
<rows Product_Id="500" Product_Code="EMISS2001" CEPC_No="EMISS2001" Product_Name="2001 SAE Emissions Technology Collection on CD-ROM (价格为非会员价)"/>
<rows Product_Id="501" Product_Name="Gene Therapy Database 1982-current on one CD"/>
<rows Product_Id="502" Product_Code="EMISS2001" CEPC_No="EMISS2001" Product_Name="2001 SAE Emissions Technology Collection on CD-ROM (价格为会员价)"/>
<rows Product_Id="503" Product_Code="ENGSI2001" CEPC_No="ENGSI2001" Product_Name="2001 SAE Spark-Ignition Engines Collection on CD-ROM (价格为非会员价)"/>
<rows Product_Id="504" Product_Code="ENGSI2001" CEPC_No="ENGSI2001" Product_Name="2001 SAE Spark-Ignition Engines Collection on CD-ROM (价格为会员价)"/>
<rows Product_Id="505" Product_Code="ALTFUEL2001" CEPC_No="ALTFUEL2001" Product_Name="SAE Alternative Fuels Technology Collection on CD-ROM (价格为非会员价)"/>
<rows Product_Id="506" Product_Code="ALTFUEL2001" CEPC_No="ALTFUEL2001" Product_Name="SAE Alternative Fuels Technology Collection on CD-ROM(价格为会员价)"/>
<rows Product_Id="507" Product_Name="SAE Automotive Fuels & Lubricants Database"/>
<rows Product_Id="508" Product_Name="SAE Materials Database (价格为一个工作站价格)"/>
<rows Product_Id="509" Product_Code="MAT2000" CEPC_No="MAT2000" Product_Name="SAE Materials Database on CD-ROM (价格为非会员价)"/>
<rows Product_Id="510" Product_Name="Patent Previews-Pharmaceutics & Synthetic Methods Subset(DISKETTE) 医物专利索引- 医药与合成方法库(磁盘)"/>
<rows Product_Id="511" Product_Name="Patent Previews-Diagnostics & Therapeutics Subset 药学专利索引及说明书光盘- 诊断治疗库(磁盘)"/>
<rows Product_Id="512" Product_Name="Immunology Today Online"/>
<rows Product_Id="513" Product_Name="EMBASE Alert CD"/>
<rows Product_Id="514" Product_Name="Ageline"/>
</root>
ssm1226 2003-05-22
  • 打赏
  • 举报
回复
代码,看看
ssm1226 2003-05-22
  • 打赏
  • 举报
回复
test.xml文件有效吗?
mgwms 2003-05-22
  • 打赏
  • 举报
回复
to ssm1226(雨中人): 而且我有另外一个程序,就可以,奇怪 不知道为什么!
mgwms 2003-05-22
  • 打赏
  • 举报
回复
不行啊!我的test.xml在同一个目录下!
ssm1226 2003-05-22
  • 打赏
  • 举报
回复
注意test.xml文件路径

设置为同步传输

async=false

8,906

社区成员

发帖
与我相关
我的任务
社区描述
XML/XSL相关问题讨论专区
社区管理员
  • XML/XSL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧