欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

asp读取xml实例代码

程序员文章站 2022-06-24 16:12:02
language.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
%>

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