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

OverthereAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

OverthereAuthor 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
0
ste5anSenior DeveloperCommented:
Why looping at all? Just emit the XML:

E.g.
<!-- saved from url=(0016)http://localhost -->
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title>Test</title>
        <style>
            SERVICEPROVIDER             { display: block; }
            SERVICEPROVIDERNAME         { display: block; }
            PROVIDERTYPE                { display: block; }
            STARTDATE                   { display: block; }
            ENDDATE                     { display: block; }
            PROVIDERTYPE::before        { content: "Provider Type is: "; }
            SERVICEPROVIDERNAME::before { content: "Provider is:"; }
            STARTDATE::before           { content: "Begin date is: "; }
            ENDDATE::before             { content: "End date is: "; }
        </style>
    </head>
    <body>
        <SERVICEPROVIDER>
            <PROVIDERTYPE>1</PROVIDERTYPE>
            <SERVICEPROVIDERNAME>2</SERVICEPROVIDERNAME>
            <STARTDATE>3</STARTDATE>
            <ENDDATE>4</ENDDATE>
        </SERVICEPROVIDER>
        <SERVICEPROVIDER>
            <PROVIDERTYPE>5</PROVIDERTYPE>
            <SERVICEPROVIDERNAME>2</SERVICEPROVIDERNAME>
            <STARTDATE>7</STARTDATE>
            <ENDDATE>8</ENDDATE>
        </SERVICEPROVIDER>
    </body>
</html>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
OverthereAuthor 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.....
0
OverthereAuthor 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.  :}
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP

From novice to tech pro — start learning today.