当前位置: 代码迷 >> ASP >> ASP怎么生成XML
  详细解决方案

ASP怎么生成XML

热度:106   发布时间:2012-09-10 22:20:12.0
ASP如何生成XML
我想用ASP生成这样的XML

<tiltviewergallery>
<photos>


<photo imageurl="imgs/1.jpg" linkurl="http://www.google.com">
<title>Image 1</title>
<description>我爱你们,哈哈</description>
</photo>




<photo imageurl="imgs/2.jpg" linkurl="http://www.google.com">
<title>Image 2</title>
<description>非常好</description>
</photo>






</photos>

</tiltviewergallery>


应该怎么办呢,其中ASP是读取数据库的

------解决方案--------------------
VBScript code

<%
Set oDoc    = CreateObject("Msxml2.DOMDocument")
With oDoc
    .async              = False
    .validateOnParse    = False
    .preserveWhiteSpace = False
    .resolveExternals   = False
End With
Set oRoot = oDoc.createElement("tiltviewergallery")
Set oDoc.documentElement = oRoot
Set oPhotos = oDoc.createElement("photos")

Do While Not rs.EOF
  Set oPhoto = oDoc.createElement("photo")
  oPhoto.setAttribute "imageurl", "imgs/1.jpg"
  oPhoto.setAttribute "linkurl", "http://www.google.com"
  Set oNode = oDoc.createElement("title")
  oNode.text = "title"
  oPhoto.appendChild oNode
  Set oNode = oDoc.createElement("description")
  oNode.text = "description"
  oPhoto.appendChild oNode
  oPhotos.appendChild oPhoto
  rs.MoveNext
Loop
oRoot.appendChild oPhotos
oDoc.scave "c:\xxx\xxx.xml"

Response.ContentType = "text/xml"
Response.Write oDoc.xml
%> 
  相关解决方案