2013-04-21 54 views
1

我不习惯使用XML,所以这可能看起来是一个愚蠢的问题。我将永远这样形成的XML文档:XML/ASP:如何获得空元素的属性值

<lists> 
    <list subscriber_count="5048" display_name="" name="GiNsubs" id="705381"/> 
</lists> 

我需要在空元素“列表”的“名称”属性的值。由于它是空的,我没有尝试过将'list'元素作为对象,所以我可以在其上使用GetAttribute。我试过GetElementbyTagName,SelectSingleNode,甚至是FirstChild,但似乎没有抓取'list'元素作为节点。作为参考,我的代码是目前如下:

valid = "No" 
Set xmldoc = Server.CreateObject("Microsoft.XMLDOM") 
Set objLst = Server.CreateObject("Microsoft.XMLDOM") 
    xmldoc.async = false 
    xmldoc.Load ("{XML document location}") 

Set objLst = xmldoc.selectsinglenode("list") 
if objLst.GetAttribute("name") = "GiNsubs" then 
    valid = "Yes" 
end if 

此目前生产的错误是“所需的对象”上的“的getAttribute”行。

任何帮助表示赞赏。

哦,顺便说一下,这个XML文档是API的内容,因此改变XML格式并不是一个真正的选择。

回答

0

下面当我试图

<% 
valid = "no" 

Set xmldoc = Server.CreateObject("Microsoft.XMLDOM") 
xmldoc.setProperty "ServerHTTPRequest", True 
xmldoc.async = False 
xmldoc.validateOnParse = False 
'stop 'uncomment to trigger a debugger break here (if you're setup for server-side debugging) 
xmldoc.Load "http://domain/subfolder/deleteme.xml" 'add your URL here 

xmlDoc.setProperty "SelectionLanguage", "XPath" 
Set objLst = xmldoc.selectsinglenode("lists/list") 
If objLst.GetAttribute("name") = "GiNsubs" Then 
    valid = "Yes" 
End If 
%> 
<html> 
<head> 
<title>XML XPath Test</title> 
</head> 
<body> 
    <%=Valid %>  
</body> 
</html> 
+0

我想工作: xmlDoc.setProperty “SelectionLanguage”, “XPath的” 设置objLst = xmlDoc.selectSingleNode( “/列表/列表”)的innerText 如果objLst.GetAttribute(“name”)=“GiNsubs”那么 valid =“是” end if 现在它给出错误“Object required:'[object]'”for line“Set objLst = xmlDoc.selectSingleNode ( “/lists/list").innerText”。 – 2013-04-21 17:44:33

+0

当你尝试了什么是trhe结果?我不太确定“Set” - 尝试没有它。你能调试吗?任何错误? – 2013-04-21 18:12:32

+0

我试着删除了第二行中的“Set” - 它给出了相同的VBscript运行时错误 - “Object required:'[object]'”。我将如何调试? – 2013-04-21 18:16:51