Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting XML data using ASP 1

Status
Not open for further replies.

stinkybee

Programmer
May 15, 2001
218
0
0
GB
I know this should be very simple but I've been searching for hours and still not found a solution.

I just need to display some simple XML date in an asp page.

Here's some sample XML data:

Code:
<ReturnVoucherObj>
  <StatusCode>0</StatusCode> 
  <StatusMsg /> 
  <Vouchers>
    <Voucher>
      <ProgrammeID></ProgrammeID> 
      <StartDate></StartDate> 
      <EndDate></EndDate> 
      <VoucherDescription></VoucherDescription> 
      <VoucherCode></VoucherCode> 
      <MerchantSiteID></MerchantSiteID> 
      <LandingPage></LandingPage> 
      <Status></Status> 
      <MerchantSiteName></MerchantSiteName> 
    </Voucher>
  </Vouchers>
</ReturnVoucherObj>

Please note the sample has no data but my real xml file does.

All I need is a nice loop to pull out all the seperate info from each "Voucher" using the node name as a heading. For example

Voucher1
ProgrammeID = sample
StartDate = 01/01/2011
.... etc

So far all I have managed to do is display all the info with no nodename heading. Here's the code so far:

Code:
set xmlDoc=Server.CreateObject("Microsoft.XMLDOM")
xmlDoc.async="false"
xmlDoc.load(Server.MapPath("voucher.xml"))
Set getVouchers = xmlDoc.getElementsByTagName("Voucher")

For i = 0 To (getVouchers.Length - 1)				
  response.write getVouchers.item(i).text & "<br /><br />"
Next

This outputs all the text from the childnodes of the "Voucher" node but I have been unable to access these childnodes seperately.

Thanks in advance for any help on this.
 
[tt]For i = 0 To (getVouchers.Length - 1)
set getVouchersChildNodes=getVourchers.item(i).ChildNodes
For j=0 To getVouchersChildNodes.Length-1
response.write getVouchersChildNodes.item(j).tagName & " = " & getVouchersChildNodes.item(j).text & "<br /><br />"
Next
Next[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top