服务器之家:专注于服务器技术及软件下载分享
分类导航

PHP教程|ASP.NET教程|Java教程|ASP教程|编程技术|正则表达式|C/C++|IOS|C#|Swift|Android|JavaScript|易语言|

服务器之家 - 编程语言 - ASP教程 - asp读取xml实例代码

asp读取xml实例代码

2019-09-06 11:51asp之家 ASP教程

asp读取xml实例代码

language.xml 

复制代码代码如下:


<?xml version="1.0" encoding="gb2312"?> 
<languageRoot> 

<!--简体中文--> 
<language> 
<LanguageName>简体中文</LanguageName> 
<LanguageValue>SimpilifiedChinese</LanguageValue> 
<LanguageImages>images</LanguageImages> 
<LanguageFile></LanguageFile> 
</language> 

<!--繁體中文--> 
<language1> 
<LanguageName>繁體中文</LanguageName> 
<LanguageValue>TraditionalChinese</LanguageValue> 
<LanguageImages>imagesBig5</LanguageImages> 
<LanguageFile>ddd</LanguageFile> 
</language1> 
</languageRoot> 


sl.asp 

复制代码代码如下:


<% 
Set objXML2 = Server.CreateObject("Msxml2.DOMDocument") 
objXML2.async = False 
loadResult = objXML2.load(Server.MapPath("language.xml")) 

if not loadResult then 
Response.write "装载XML文件错误" 
Response.end 
end If 
Set objNodes = objXML2.getElementsByTagName("languageRoot/language") 
For i = 0 to objNodes.length - 1 
Response.write Trim(objNodes(i).selectSingleNode("LanguageName").Text)&"<br>" 
Response.write Trim(objNodes(i).selectSingleNode("LanguageValue").Text)&"<br>" 
Response.write Trim(objNodes(i).selectSingleNode("LanguageImages").Text)&"<br>" 
Next 
set objNodes = Nothing 
Set objNodes = objXML2.getElementsByTagName("languageRoot/language1") 
For i = 0 to objNodes.length - 1 
Response.write Trim(objNodes(i).selectSingleNode("LanguageName").Text)&"<br>" 
Response.write Trim(objNodes(i).selectSingleNode("LanguageValue").Text)&"<br>" 
Response.write Trim(objNodes(i).selectSingleNode("LanguageImages").Text)&"<br>" 
Response.write Trim(objNodes(i).selectSingleNode("LanguageFile").Text)&"<br>" 
Next 
set objNodes = Nothing 
Set objXML = Nothing 
%> 


以上代码,经服务器之家编辑测试通过。

延伸 · 阅读

精彩推荐