Avatar of Overthere
Overthere
 asked on

ASP and Looping Thru a XML Document

I have a xml document that I wish to loop thru and extract data. The page is working fine but I think it could be coded much efficiently.
In my original coding vIndex was increment and I had a loop etc. It's just messy.
I have posted my new coding and old coding.
The new coding gives me o  from objNodeList.length statement.
What am I doing wrong??
new coding below
	set objNodeList = xdDoc.getElementsByTagName("SERVICEPROVIDER")	
	response.write "<BR>" & objNodeList.length
	if xdDoc.parseError = 0 then
	  if objNodeList.length > 0 then
	     for each x in objNodeList
		     response.write "<BR> inside for/next"
	             vprovider = x.getattribute("SERVICEPROVIDERNAME")
                     vbegdate = x.getattribute("STARTDATE")
                    venddate = x.getattribute("ENDDATE")
	    	     response.write "<BR>Provider is: " & vprovider & "   Startdate: " & vbegdate & "  Ending Date: " & venddate               
		next
	   end if
	 else
        ' display error message
    end if 	 

Open in new window


And this is old coding and was how I was doing looping but messy - incrementing vIndex
               wrkname = SERVICECARD/SERVICEINFO/SERVICEPROVIDERLIST/SERVICEPROVIDER[" & vIndex & "]/SERVICEPROVIDERNAME"
	      wrkstartdate = xdDoc.selectSingleNode("SERVICECARD/SERVICEINFO/SERVICEPROVIDERLIST/SERVICEPROVIDER[" & vIndex & "]/STARTDATE").text
             wrkenddate=  xdDoc.selectSingleNode("SERVICECARD/SERVICEINFO/SERVICEPROVIDERLIST/SERVICEPROVIDER[" & vIndex & "]/ENDDATE").text

Open in new window

ASPXML

Avatar of undefined
Last Comment
Overthere

8/22/2022 - Mon
Overthere

ASKER
I solved it: this is what my coding looks like now:
Set colNodes = xdDoc.selectNodes ("//SERVICEPROVIDER")
      
      if xdDoc.parseError = 0 then
           for each objSite in colNodes
                 response.write "<BR> inside for/next"
                   vsegnbr = objSite.selectSingleNode("PROVIDERTYPE").text
                      vprovider = objSite.selectSingleNode("SERVICEPROVIDERNAME").text
                    vbegindate = objSite.selectSingleNode("STARTDATE").text
                    venddate = objSite.selectSingleNode("ENDDATE").text
                    response.write "<BR>Provider Type is: " & vsegnbr
                  response.write "<BR>Provider is: " & vprovider
                  response.write "<BR>Begin date is: " & vbegindate
                  response.write "<BR>End date is: " & venddate
            next
       else
        ' display error message
    end if       
        
      response.end
ASKER CERTIFIED SOLUTION
ste5an

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Overthere

ASKER
Thank you for responding. There is much more that goes on behind the scenes than what was posted. Data is extracted, validated and populated into tables and etc.....
Overthere

ASKER
Thank you - its a good piece of coding to display values. Wasn't quite what I need (I resolved the issue myself).  But I appreciate you sharing and responding.  :}
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck