Click to See Complete Forum and Search --> : Navigating the XML DOM using VBScript


sheila
05-27-2003, 11:41 AM
I need to check whether or not a node exists using a known node name and attribute (eg. <post id="POS269">) and then whether it has a specific grandchild (<teacher />). I've managed to complete the first step:

dim xmlDom, nodeList, seeking, requirements
set xmlDom = server.createobject("MSXML2.DOMDocument")
xmlDom.async = false
xmlDom.load backstage & "/xml/organisation.xml"
seeking = "//post[@id='" & session("applying_for") & "']"
set nodeList = xmlDom.documentElement.selectSingleNode(seeking).childNodes

but can't work out how to check for the grandchild.

Also can anyone recommend any good websites or books for using the XML DOM with VBScript?

khalidali63
05-27-2003, 03:31 PM
if MS DOM follows the DOM standards then you should be able to get this using
nodeList[index].lastChild()...

depending upon what syntax MS uses

sheila
05-28-2003, 08:47 AM
Tried your suggestion but it doesn't like the square brackets.

for each x in nodeList
if x.nodename = "requirements" then
response.write nodeList[x].lastchild()
end if
next

Error: Expected end of statement

And when I tried it with round brackets I got a type mismatch error.

khalidali63
05-28-2003, 10:11 AM
now that really sucks...( I hope I am not doing anything wrong here)

set nodeList = xmlDom.documentElement.selectSingleNode(seeking).childNodes

oh cripes....hey change nodeList to something else..nodeList is a dom keyword.

sheila
05-28-2003, 09:12 PM
Have changed the name already but no change. Thanks anyway. Am very new to the XML Dom (in case you hadn't already guessed!)

sheila
05-29-2003, 07:59 PM
Figured it out.

set requirements = x.childnodes
for each z in requirements
if z.nodename = "teacher" then
session("form") = "teacher"
end if
next

Obvious! :rolleyes:

khalidali63
05-29-2003, 08:01 PM
****es...MS does not follow DOM at at all....
childnodes....

in dom its

element.childNodes