Logic and Syntax for Node Iteration

G

Gregg

Hello;

I have the below XML schema which I'm trying to iterate through node by
node. The script I'm using is also shown below. The resulting output,
also shown below, shows that I'm not reaching the element "tblTestCase"
nor the attribute names "TeamID" and "ProdID". How should I change my
script to make it follow the nodes all the way through?

Thanks,
Gregg

Please note that I've modified the XML for brevity and also so that it
isn't read as xml code by the post.

xsd:schema
targetNamespace="http://schemas.microsoft.com/office/infopath/2003/ado/d
ataFields" elementFormDefault="unqualified"
attributeFormDefault="unqualified"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:d="http://schemas.microsoft.com/office/infopath/2003/ado/dataField
s"
xsd:element name="tblTestCase"
xsd:complexType
xsd:attribute name="TeamID" use="optional"
xsd:simpleType
xsd:restriction base="xsd:string"
xsd:maxLength value="10"/
/xsd:restriction
/xsd:simpleType
/xsd:attribute
xsd:attribute name="ProdID" use="optional"
xsd:simpleType
xsd:restriction base="xsd:string"
xsd:maxLength value="10"/
/xsd:restriction
/xsd:simpleType
/xsd:attribute

OUTPUT FILE:
NodeName NodeType
++++++++ ++++++++++
mso-application progid="InfoPath.Document" 7
dfs:myFields 1
dfs:queryFields 1
dfs:queryFields 1
#text 3
dfs:dataFields 1
#text 3
my:FileAttachment 1
#text 3
my:passFail 1
#text 3


Code:
set oNodeList = root.childnodes
MoreNodes = True
Do While MoreNodes
  i = 0
  Display_NodeList oNodeList, i, MoreNodes

Loop

Sub Display_NodeList(varNodeList, varIndex, boolMoreNodes)
boolMoreNodes = False
For Each Item In varNodeList
     varIndex = varIndex + 1
     if varIndex < varNodeList.length then
        strTextLine=varNodeList.item(varIndex).nodename & " " &
varNodeList.item(varIndex).nodevalue & " " &
varNodeList.item(varIndex).nodetype
        write_lines strTextLine
        'msgbox "Listing the EXISTING nodes"
        'MsgBox varNodeList.item(varIndex).nodename & " " &
varNodeList.item(varIndex).nodevalue & " " &
varNodeList.item(varIndex).nodetype
        If varNodeList.item(varIndex).hasChildNodes() then
           boolMoreNodes = True
           MsgBox varNodeList.item(varIndex).nodename & "has child
nodes"
           IF varNodeList.length = 9 then
              do while i3 < 9
                 i3 = i3 + 1
                 strTextLine=varNodeList.item(i3).nodename & " " &
varNodeList.item(i3).nodevalue & " " & varNodeList.item(i3).nodetype
                 write_lines strTextLine
              loop
              'msgbox varNodeList.item(1).nodename
              'msgbox varNodeList.item(2).nodename
              'msgbox varNodeList.item(3).nodename
              'msgbox varNodeList.item(4).nodename
              'msgbox varNodeList.item(5).nodename
              'msgbox varNodeList.item(6).nodename
              'msgbox varNodeList.item(7).nodename
              'msgbox varNodeList.item(8).nodename
              'msgbox varNodeList.item(9).nodename
           end if
           'set oNodeList2 =
root.getelementsbytagname(oNodeList.item(i).nodename)
           set varNodeList = varNodeList.item(varIndex).childnodes
           varIndex=0
           'set oNodeList2 =
oNodeList.selectnodes(oNodeList.item(i).nodename)
           'set oNodeList2 =
root.selectnodes(oNodeList.item(i).nodename)
        end if
        if varNodeList.item(varIndex).nodeType = 3 then
           MsgBox "TEXT NODE: " & varNodeList.item(varIndex).nodename &
" " & varNodeList.item(varIndex).nodevalue & " " &
varNodeList.item(varIndex).nodetype
           MSGBOX varNodeList.item(varIndex).text
        end if
        if varNodeList.item(varIndex).nodeType = 4 then
           MsgBox "ATTR NODE: " & varNodeList.item(varIndex).nodename &
" " & varNodeList.item(varIndex).nodevalue & " " &
varNodeList.item(varIndex).nodetype
           MSGBOX varNodeList.item(varIndex).text
        end if
     end if
Next
        
end sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top