asp读取xml实例代码

编程学习 2021-07-05 10:58www.dzhlxh.cn编程入门
读取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
%>

以上代码,经狼蚁SEO编辑测试通过。

Copyright © 2016-2025 www.dzhlxh.cn 金源码 版权所有 Power by

网站模板下载|网络推广|微博营销|seo优化|视频营销|网络营销|微信营销|网站建设|织梦模板|小程序模板