We help IT Professionals succeed at work.

ASP and Looping Thru a XML Document

Overthere
Overthere asked
on
172 Views
Last Modified: 2017-04-01
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

Comment
Watch Question

Author

Commented:
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
Senior Developer
CERTIFIED EXPERT
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION

Author

Commented:
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.....

Author

Commented:
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.  :}