当前位置: 首页 > 网络学院 > XML相关教程 > XML > XML 服务器

XML
XML 介绍
XML 的用途
XML 语法规则
XML 元素
XML 属性
XML 的有效性验证
XML 校验器
支持 XML 的浏览器
浏览 XML 文件
用 CSS 显示 XML
用 XSL 显示 XML
XML 数据岛
XML 解析器
现实中的 XML
XML 命名空间
XML CDATA
XML 服务器
XML 应用程序
XMLHttpRequest 对象
XML 保存数据

XML 服务器


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-03-01   浏览: 649 ::
收藏到网摘: n/a

XML can be generated on a server without installing any XML controls.
无须安装任何XML控件就可以在服务器上生成XML文件。


Storing XML on the Server
在服务器上储存xml

XML files can be stored on an Internet server exactly the same way as HTML files.
XML文件在Internet 服务器上的储存方式与HTML文件完全相同。

Start Windows Notepad and write the following lines:
打开Windows 记事本,并书写下面的代码:

<?xml version="1.0" encoding="ISO-8859-1"?>

<note>
<from>Jani</from>
<to>Tove</to>
<message>Remember me this weekend</message>

</note>

Save the file on your web server with a proper name like "note.xml".
给文件起个恰当的名字(如:note.xml),并将其保存在网络服务器上。


Generating XML with ASP
利用ASP生成XML

XML can be generated on a server without any installed XML software.
无须安装任何XML软件就可以在服务器上生成XML。

To generate an XML response from the server - simply write the following code and save it as an ASP file on the web server:
为了在服务器端产生一个XML响应——只须简单写下如下的代码,并在网络服务器上把它保存为一份ASP文件

<%
response.ContentType="text/xml"

response.Write("<?xml version='1.0' encoding='ISO-8859-1'?>")
response.Write("<note>")
response.Write("<from>Jani</from>")
response.Write("<to>Tove</to>")
response.Write("<message>Remember me this weekend</message>")
response.Write("</note>")
%>

Note that the content type of the response must be set to "text/xml".
注意回复的内容类型必须设置为"text/xml"。

See how the ASP file will be returned from the server.
看看从服务器返回的ASP文件里有些什么.

If you don't know how to write ASP, please visit our ASP tutorial
如果你不知道怎么写ASP,可以访问我们的 ASP教程


Getting XML From a Database
从数据库得到XML形式数据

XML can be generated from a database without any installed XML software.
没有安装任何XML软件就可以从数据库中产生XML。

To generate an XML database response from the server, simply write the following code and save it as an ASP file on the web server:
为了从服务器得到XML数据库响应,只须书写下述代码,并在网络服务器上把它保存为一份ASP文件就可以了:

<%
response.ContentType = "text/xml"
set conn=Server.CreateObject("ADODB.Connection")
conn.provider="Microsoft.Jet.OLEDB.4.0;"
conn.open server.mappath("/db/database.mdb")
sql="select fname,lname from tblGuestBook"
set rs=Conn.Execute(sql)
rs.MoveFirst()
response.write("<?xml version='1.0' encoding='ISO-8859-1'?>")
response.write("<guestbook>")
while (not rs.EOF)
response.write("<guest>")
response.write("<fname>" & rs("fname") & "</fname>")
response.write("<lname>" & rs("lname") & "</lname>")
response.write("</guest>")
rs.MoveNext()
wend
rs.close()
conn.close()
response.write("</guestbook>")
%>

See the real life database output from the ASP file above.
看看上述ASP文件中的数据库的实际输出情况.

The example above uses ASP with ADO. If you don't know how to use ADO, please visit our ADO tutorial.
上述的案例使用了ASP,并在ASP中运用了ADO。如果你对ADO的用法还不了解,可以查阅我们的 ADO 教程

评论 (0) All

登陆 | 还没注册?