Logic and Syntax for Node Iteration

Discussion in 'XML' started by Gregg, Jun 9, 2007.

  1. Gregg

    Gregg Guest

    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
    
    *** Sent via Developersdex http://www.developersdex.com ***
     
    Gregg, Jun 9, 2007
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    1,669
  2. Cuperman

    NodeList iteration and node edit

    Cuperman, Jan 24, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    847
  3. Tjerk Wolterink
    Replies:
    2
    Views:
    1,520
    Dimitre Novatchev
    Aug 24, 2006
  4. Rudi
    Replies:
    5
    Views:
    5,319
  5. spike
    Replies:
    8
    Views:
    1,546
    Steve Holden
    Feb 9, 2010
Loading...

Share This Page