webmasterbeta
New Member
Hi Guys,
(I'll pre-empt this by saying that I'm a newbie to XML, so please go easy on me )
I'm trying to use some XPath commands such as [position()<3] with .asp/VBScript, but when I try it I get an error message:
msxml3.dll error '80004005'
Unknown method. Houses/House
(I'll pre-empt this by saying that I'm a newbie to XML, so please go easy on me )
I'm trying to use some XPath commands such as [position()<3] with .asp/VBScript, but when I try it I get an error message:
msxml3.dll error '80004005'
Unknown method. Houses/House
Code:
/Items/Item[-->position()<--<3]
I've found out that apparently I can fix this by adding:
domDoc.setProperty "SelectionLanguage", "XPath"
- i tried this out on one of the examples on the w3schools.com website (<!-- m --><a class="postlink" href="http://www.w3schools.com/xpath/tryit.asp?filename=try_xpath_select_pricenodes_35">http://www.w3schools.com/xpath/tryit.as ... cenodes_35</a><!-- m -->)
(copy the code below into the test facility at the URL above to see what I mean)
<html>
<body>
<script type="text/vbscript">
set xmlDoc=CreateObject("Microsoft.XMLDOM")
xmlDoc.async="false"
xmlDoc.load("books.xml")
xmlDoc.setProperty "SelectionLanguage", "XPath"
set nodes=xmlDoc.selectNodes("/bookstore/book[title='XQuery Kick Start']/author[position()<3]")
for each x in nodes
document.write("<xmp>")
document.write(x.xml)
document.write("</xmp>")
next
</script>
</body>
</html>
.... and it worked a treat (i.e. - I could limit the number of authors returned) and so I thought I had the problem solved.
...but when I applied the same logic to my code I get:
Microsoft VBScript runtime error '800a01a8'
Object required
... at the very first XML /asp object it encounters.
Here's the code I'm using:
<%@ Language=VBScript %>
<% Set domDoc = server.CreateObject("MSXML.DOMDocument")
domDoc.async = False ' load all of the XML file first
domDoc.setProperty "SelectionLanguage", "XPath" ' declare that we absolutely want to use XPath so that the "position()" attribute works
Response.Buffer = False ' set buffer to False so that page loads OK due to larger than normal file size
Server.ScriptTimeout = 1200 ' set timeout to 20 minutes
aFilename = server.MapPath("../xml/demo.xml")
if NOT domDoc.Load(aFilename) then
response.write "Could not load file " & afilename & "<br />"
response.end
end if
Set aNode = domDoc.documentElement
%>
<html>
<head>
</head>
<meta name="robots" content="noindex, nofollow" />
<body>
<%
count = -1
Set Houses = domDoc.SelectNodes("Houses/House")
for each House in Houses
count = count + 1
Set Code = domDoc.SelectSingleNode("Houses/House[" & count & "]/Code")
response.write "The code is: " & Code.Text & "<br />"
Set item= domDoc.SelectNodes("Houses/House[" & count & "]/Items/Item[position()<3]")
response.write "The item is: " & item.Text & "<br />"
next
%>
</body>
</html>
Any ideas?
Thanks
Kessa