delphi programming forums mysql charset mget recursive synonimos
free ventrilo servers hosting cs javascript delay python find in list
Back Forum New
abstract:

I can get info from the higher level child nodes but nothing from the lower nodes. I am kind of stuck atm.
code such as this:
PHP Code:
<
script type
=
"text/vbscript"
>
set xmlDoc
=
CreateObject
(
"Microsoft.XMLDOM"
)
xmlDoc
.
async
=
"false"
xmlDoc
.
load
(
"note.xml"
)
for
each x in xmlDoc
.
documentElement
.
childNodes
    document
.
write
(
x
.
nodeName
&
"<br />"
)
next
</script>
will not show me the lowest level node info.


I am trying to bone up on XML, and have been reading the tutorials posted here and W3S and others.
I am trying to parse through some XML files that have multiple siblings... But cannot seem to fins out how to get the DOM to see these siblings.
here is an example
PHP Code:
<
main
>
    <
updated
>
Mon Feb 17 13
:
17
:
59 2003
</
updated
>
    <
baseinfo
>
        <
stata
>
60
</
stata
>
        <
statb
>
70
</
statb
>
        <
statc
>
83
</
statc
>
    </
baseinfo
>
    <
equipment
>
        <
inventory
>
            <
item
>
                <
devicea
>
1334
</
devicea
>
                <
deviceb
>
5713
</
deviceb
>
                <
devicec
>
234
</
devicec
>
            </
item
>
                                </
inventory
>
    </
equipment
>
</
main
>
I have been using some of the DOM test examples but cannot seem to parse out the info from the statx siblings.
I can get info from the higher level child nodes but nothing from the lower nodes. I am kind of stuck atm.
code such as this:
PHP Code:
<
script type
=
"text/vbscript"
>
set xmlDoc
=
CreateObject
(
"Microsoft.XMLDOM"
)
xmlDoc
.
async
=
"false"
xmlDoc
.
load
(
"note.xml"
)
for
each x in xmlDoc
.
documentElement
.
childNodes
    document
.
write
(
x
.
nodeName
&
"<br />"
)
next
</script>
will not show me the lowest level node info.

TOP

Your script is only iterating through the first level of children.
In order to get to the "root" of the problem (ha ha,) use this code instead:
<script type="text/vbscript">
set xmlDoc=CreateObject("Microsoft.XMLDOM")
xmlDoc.async="false"
xmlDoc.load("note.xml")
set xmlRootNode = xmlDoc.documentElement
set xmlNodeList = xmlRootNode.selectNodes("/main/baseinfo/*")
For i = 0 To xmlNodeList.length - 1
    document.write(xmlNodeList.Item(i).nodeName & "<br />")
Next
</script>
I haven't tested it, but the basic idea is, xpath a selectNodes statement to the level you need.  I can give you more help or specifics if you need it.

TOP

Forgot this: If you want to cycle through all the children, create a recursive function.

TOP

Thanks for the tips Custom, I will have to play with this this weekend, as these concepts are a tad new to me.

TOP

abstract:

I can get info from the higher level child nodes but nothing from the lower nodes. I am kind of stuck atm.
code such as this:
PHP Code:
<
script type
=
"text/vbscript"
>
set xmlDoc
=
CreateObject
(
"Microsoft.XMLDOM"
)
xmlDoc
.
async
=
"false"
xmlDoc
.
load
(
"note.xml"
)
for
each x in xmlDoc
.
documentElement
.
childNodes
    document
.
write
(
x
.
nodeName
&
"<br />"
)
next
</script>
will not show me the lowest level node info.


I would be happy to email you some example VBScript code along with lists of necessary libraries if you require additional assitance.

TOP

I'm having a similar problem with reading a file. The example you listed doesn't really apply to me. I searched and this was the closest thing I could find...
PHP Code:
<
Questions
>
    <
Question sequence
=
"0"
>
        <
QuestionText
>
How old are you
?</
QuestionText
>
        <
Answers
>
            <
Answer sequence
=
"1"
correct
=
"N"
>
                <
AnswerText
>
20
</
AnswerText
>
            </
Answer
>
            <
Answer sequence
=
"2"
correct
=
"N"
>
                <
AnswerText
>
22
</
AnswerText
>
            </
Answer
>
            <
Answer sequence
=
"3"
correct
=
"N"
>
                <
AnswerText
>
28
</
AnswerText
>
            </
Answer
>
            <
Answer sequence
=
"4"
correct
=
"Y"
>
                <
AnswerText
>
27
</
AnswerText
>
            </
Answer
>
            <
Answer sequence
=
"5"
correct
=
"N"
>
                <
AnswerText
>
None of the above
</
AnswerText
>
            </
Answer
>
        </
Answers
>
    </
Question
>
</
Questions
>
I'm trying to get to the Question Text and the answers. Here's what I'm trying that's not working.
PHP Code:
Set obj_questions
=
objXMLReceive
.
getelementsbytagname
(
"Question"
)
For
i
=
0 to obj_questions
.
length
-
1
    Set obj_question
=
obj_questions
(
i
)
s_questxt
=
obj_question
.
selectSingleNode
(
"QuestionText"
)
myArray
(
i
) =
s_questxt
    Set obj_answers
=
objXMLReceive
.
getelementsbytagname
(
"Answers"
)
    For
j
=
0 to obj_answers
.
length
-
1
        Set obj_answer
=
obj_answers
(
j
)
s_answertxt
=
obj_answer
.
selectSingleNode
(
"Answer"
)
s_correct
=
obj
.
answer
.
getAttribute
(
"correct"
)
myAnswers
(
j
) =
s_answertxt
    Next
Next
My error occurs here:
PHP Code:
s_questxt
=
obj_question
.
selectSingleNode
(
"QuestionText"
)
Any and all help would be appreciated.
Thanks,
Steve

TOP

the error probably occurs because you're selecting a node object into a text variable.  I would try something like
s_questxt  = obj_question.selectSingleNode("QuestionText\text()")
Or use a two step method to set x = node object, then get the text property of that object.  I'm short on time right now so there's not a lot of code in this reply, but I hope it helps!

TOP

Thanks! I actually found the answer while I was playing around. Thanks,
Steve



I can get info from the higher level child nodes but nothing from the lower nodes. I am kind of stuck atm.
code such as this:
PHP Code:
<
script type
=
"text/vbscript"
>
set xmlDoc
=
CreateObject
(
"Microsoft.XMLDOM"
)
xmlDoc
.
async
=
"false"
xmlDoc
.
load
(
"note.xml"
)
for
each x in xmlDoc
.
documentElement
.
childNodes
    document
.
write
(
x
.
nodeName
&
"<br />"
)
next
</script>
will not show me the lowest level node info.

TOP

Back Forum