asp读取xml实例代码
程序员文章站
2022-03-04 16:56:57
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
%>
以上代码,经编辑测试通过。
复制代码 代码如下:
<?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
%>
以上代码,经编辑测试通过。
上一篇: Ajax内部交流文档