Article last modified on 2002-1-21
<%Response.Buffer = False%> <html> <head> </head> <body> <% Dim oXML, oXMLError, ReturnValue, x Set oXML = Server.CreateObject("MSXML2.DOMDocument")
' 设置DOMDocument加载资源时是异步加载,还是同步加载: A oXML.async = false ' 设置目的: ' True/False value indicating if the "server-safe" ServerXMLHTTP ' component should be used to load a document to a server B oxml.setProperty "ServerHTTPRequest", true ' 通过HTTP加载资源: C ReturnValue = oXML.Load("http://localhost/asp/ServerXML.xml") ' 或者加载文件资源: D 'ReturnValue = oXML.Load("C:Inetpub estASPServerXML.xml")
' 打出DOMDocument.load的返回值: Response.write "Result of load method is =" & ReturnValue & "<br>" ' 打出DOMDocument加载资源的URL: Response.Write oxml.url & "<br>"
'如果DOMDocument.load方法返回值为FALSE,则打出它的错误原因: If ReturnValue = False Then Response.Write "--****************--" & "<br>"
Set oXMLError = oXML.ParseError Response.Write "" & _ oXMLError.ErrorCode & _ " - " & oXMLError.Reason & _ "<br>" Set oXMLError = Nothing
Response.Write "--****************--" & "<br>" End If ' 打出加载的XML文档的节点个数 For x = 0 to oxml.childNodes.length Response.Write "Node " & x & "." & "<br>" Next
' 打出加载的XML文档内容: Response.Write "<-- XML Content: -->" & "<br>" & oxml.xml & "<br>" & " --------" Set oXML = Nothing %> </body> </html> |
A ‘ oXML.async = false
B ‘ oxml.setProperty "ServerHTTPRequest", true
这时候,加载会成功。 ReturnValue将会是TRUE。 但是加载到DOMDocument中的XML文档为空!也就是说,load方法返回的TRUE是一个幌子! 结果如下所示: