[英]Reading XML in classic ASP
I am trying to extract some XML into classic ASP for an old site. 我正在尝试将一些XML提取到旧站点的经典ASP中。
I can make it work for one example but not another. 我可以使它适用于一个示例,而不能适用于另一个示例。 I am wondering if anybody can let me know what I need to do to get them both running.
我想知道是否有人可以让我知道让他们两个都需要做的事情。 Thanks in advance.
提前致谢。
Working example 工作实例
Dim o2, oXML2
Set oXML2 = Server.CreateObject("Msxml2.DOMDocument.6.0")
Set o2 = Server.CreateObject("Msxml2.ServerXMLHTTP.6.0")
o2.open "GET", "https://api.eveonline.com/eve/CharacterID.xml.aspx?names=BorisKarlov", False
o2.send
xml2 = o2.responseText
oXML2.LoadXML xml2
response.Write oXML2.selectSingleNode("//currentTime").Text
Failing example 失败的例子
Dim o, oXML
Set oXML = Server.CreateObject("Msxml2.DOMDocument.6.0")
Set o = Server.CreateObject("Msxml2.ServerXMLHTTP.6.0")
o.open "GET", "http://api.freelancer.com/User/Properties.xml?id=sulung81", False
o.send
xml = o.responseText
oXML.LoadXML xml
response.Write oXML.selectSingleNode("//url").Text
The failing example has an XML namespace set ( xmlns="http://api.freelancer.com/schemas/xml-0.1"
). 失败的示例具有XML名称空间集(
xmlns="http://api.freelancer.com/schemas/xml-0.1"
)。
All elements in this file are in that namespace. 该文件中的所有元素都在该命名空间中。 You must use it when you select nodes.
选择节点时必须使用它。
Dim oXML, node
Set oXML = Server.CreateObject("Msxml2.DOMDocument.6.0")
oXML.load "http://api.freelancer.com/User/Properties.xml?id=sulung81"
oXML.setProperty "SelectionNamespaces", "xmlns:fl='http://api.freelancer.com/schemas/xml-0.1'"
Set node = oXML.selectSingleNode("/fl:profile/fl:url")
If Not node Is Nothing
Response.Write node.Text
End If
Notes 笔记
.load()
method to load a file directly from an URL. .load()
方法直接从URL加载文件。 There is no need for an extra ServerXMLHTTP
object. ServerXMLHTTP
对象。 selectSingleNode()
- it might be Nothing
. selectSingleNode()
的结果-可能为Nothing
。 fl
. fl
。 /fl:profile/fl:url
is better than //fl:url
. /fl:profile/fl:url
比//fl:url
更好。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.