asp xml对象转换为string

'xml文件中没有属性的情况

Dim xmlStr
xmlStr="<root><count>1</count><error>0</error><table><tr><th>表头1</th><th>表头2</th><th>表头3</th></tr><tr><td>内容1</td><td>内容4</td><td>内容3</td></tr><tr><td>内容4</td><td>内容5</td><td>内容6</td></tr></table></root>"
Dim objClass,i,j,x
Set objClass=Server.CreateObject("MSXML2.DOMDocument")
objClass.preserveWhiteSpace = true
objClass.async = false
x=objClass.loadXML(xmlStr)
if not x then
 Response.Write("read XML string error")
end if
Dim strOut
strOut=""
Dim xmlNode,x1,oNode
Set xmlNode=objClass.documentElement
strOut=strOut&xmlChild(xmlNode)

Response.Write(strOut=xmlStr)'

'下面是用到的函数

Function xmlChild(x)
 Dim strOut,x1
 strOut=""
 strOut=strOut&xmlHead(x.nodename)
 If x.ChildNodes.length>1 then
  for each x1 in x.ChildNodes
   strOut=strOut&xmlChild(x1)
  Next
 else
  strOut=strOut&x.text
 End If
 strOut=strOut&xmlFoot(x.nodename)
 xmlChild=strOut
End Function
Function xmlHead(x)
 xmlHead="<" & x & ">"
End Function
Function xmlFoot(x)
 xmlFoot="</" & x & ">"
End Function

Function xmlChild(x)'函数的另一种形式
 Dim strOut,x1
 strOut=""
 If x.hasChildNodes then
  strOut=strOut&xmlHead(x.nodename)
  for each x1 in x.ChildNodes
   strOut=strOut&xmlChild(x1)
  Next
  strOut=strOut&xmlFoot(x.nodename)
 else
  strOut=strOut&x.text
 End If
 xmlChild=strOut
End Function

上一篇:Java异常与运行时异常,以及与线程的关系


下一篇:Plugin with id 'com.novoda.bintray-release' not found的解决方法