Re: Display childNode length of XML file

From: James Campbell (james_at_stuttersystems.com)
Date: 11/11/04


Date: Thu, 11 Nov 2004 15:34:44 +0000 (UTC)

Sorted the problem but now I have another one (the updated code is below).

I need to be able to count the number of elements that exist in a node then
loop through the names and the values.

For example:

<CurrentAddress Years="6" Months="0">

I need to get the name 'Years' and 'Months' back with there corresponding
values.

Again any help would be appreciated.

regards
James

set xmlDoc=CreateObject("Microsoft.XMLDOM")
xmlDoc.async="false"
xmlDoc.load(Server.MapPath("../created_textfiles/ftp/" & varfile))

'response.write varfile & "<br><br>"

for each x in xmlDoc.documentElement.childNodes

response.write "<b>" & x.nodename & "</b><br>"

'##### get elements here ########

if x.childNodes.length <> 0 then

y = -1
while y <> x.childNodes.length - 1
y = y + 1

if x.childNodes(y).childNodes.length >= 2 then

response.write "<br>"
response.write "<strong>" & x.childNodes(y).nodename & "</strong><br>"

z = -1
while z <> x.childNodes(y).childNodes.length - 1
z = z + 1

response.write x.childNodes(y).childNodes(z).nodename & ": " &
x.childNodes(y).childNodes(z).text & "<br>"

wend

else
response.write x.childNodes(y).nodename & ": " & x.childNodes(y).text &
"<br>"
end if

'response.write "<br>"

wend

end if

response.write "<br><br>"
next

"James Campbell" <james@stuttersystems.com> wrote in message
news:cmvpif$nm2$1@hercules.btinternet.com...
> Hi,
>
> I have an xml file (that I have attatched) that I need to get values and
> node names from.
>
> I can easily get out the first level of nodes and names:
> x.childNodes(y).nodename
> x.childNodes(y).text
>
> (see the rest of the code below)
>
> However sometimes the x.childNodes(y).text contain child nodes and I am
> having difficulty splitting these values out line by line.
>
> I don't want to access the nodes by the getElementsByTagName command as
the
> xml file constantly changes.
>
> Any help would be appreciated.
>
> Thanks
> James Campbell
> Stutter Systems
>
>
>
>
>
>
>
>
> set xmlDoc=CreateObject("Microsoft.XMLDOM")
> xmlDoc.async="false"
> xmlDoc.load(Server.MapPath("../created_textfiles/ftp/" & varfile))
>
> for each x in xmlDoc.documentElement.childNodes
>
> response.write "<b>" & x.nodename & "</b><br>"
> response.write x.text & "<br><br>"
>
> if x.childNodes.length <> 0 then
>
> y = -1
> while y <> x.childNodes.length - 1
> y = y + 1
>
> '########## NEW CODE NEEDED HERE######
>
> response.write x.childNodes(y).nodename & ": " & x.childNodes(y).text &
> "<br>"
>
> wend
>
> end if
>
> response.write "<br><br>"
> next
>
>
>