Link to home
Start Free TrialLog in
Avatar of Overthere
Overthere

asked on

XML in Classic ASP

I have a question that hopefully someone can answer very quickly.  I'm trying to read in an XML file and extract data from it.  The following is a portion of the XML and also my code (the file/folder location is correct when I have it displayed):

    vfolder = txtFolder.value
    vfile = txtFile.value
    vlocation = vfolder & vfile    
    set xdDoc = Server.CreateObject("MSXML2.DOMDocument")
    xdDoc.load(vlocation)
    for each objItem In xdDoc.selectNodes("Response/Trip")
        vtype = "T"
        vtripid = objItem.selectSingleNode("id").text
        vtripdate = objItem.selectSingleNode("start_date").text
        vdisplayname = objItem.selectSingleNode("display_name").text
        vtriplocation = objItem.selectSingleNode("primary_location").text
        vprofileref = ojbItem.Attributes.getNamedItem("profile_ref").value
Response.Write "Type = " & vtype & "<br>"
Response.Write "TripId = " & vtripid & "<br>"
Response.Write "TripDate = " & vtripdate & "<br>"
Response.Write "Display_Name = " & vdisplayname & "<br>"
Response.Write "Location = " & vtriplocation & "<br>"
Response.Write "ProfileRef = " & vprofileref & "<br><br>"
    next
   
I have rearranged this so often, that I'm driving myself crazy and it's probably a very simple fix!  I've most likely screwed it up worse than when I started... So any/all assistance is appreciated!  My goal is to be able to first read through and document all the TRIPS and then go through again and document all the profiles.  So I would like to use a for/next loop.

Here is the XML:

- <Response>
  <timestamp>1355152311</timestamp>
  <num_bytes>3240</num_bytes>
 - <Trip>
   - <TripInvitees>
      - <Invitee profile_ref="OjMfu7ahFBno_TZ966pnFw">
         <is_read_only>false</is_read_only>
         <is_traveler>false</is_traveler>
         <is_owner>true</is_owner>
       </Invitee>
     - <Invitee profile_ref="bQBFJxFyGL8D0RQItvLj5w">
        <is_read_only>false</is_read_only>
        <is_traveler>true</is_traveler>
       </Invitee>
    </TripInvitees>
    <id>32960045</id>
    <relative_url>/trip/show/id/32960045</relative_url>
    <start_date>2012-12-30</start_date>
    <end_date>2013-01-06</end_date>
    <display_name>disney</display_name>
    <image_url>https://www.tripit.com/images/places/default-plane.png</image_url>
    <is_private>true</is_private>
    <primary_location>Orlando, FL</primary_location>
    - <PrimaryLocationAddress>
       <address>Orlando, FL</address>
       <city>Orlando</city>
       <state>FL</state>
       <zip>32885</zip>
       <country>US</country>
       <latitude>28.538335</latitude>
       <longitude>-81.379237</longitude>
      </PrimaryLocationAddress>
   - <TripPurposes>
       <purpose_type_code>L</purpose_type_code>
       <is_auto_generated>false</is_auto_generated>
     </TripPurposes>
     <last_modified>1354851203</last_modified>
  </Trip>
- <Profile ref="OjMfu7ahFBno_TZ966pnFw">
     <is_client>false</is_client>
     <is_pro>false</is_pro>
     <screen_name>darlene101</screen_name>
     <public_display_name>Darlene Green</public_display_name>
     <profile_url>people/darlene101</profile_url>
     <home_city>Ashland, KY</home_city>
  </Profile>
- <Profile ref="bQBFJxFyGL8D0RQItvLj5w">
  - <ProfileEmailAddresses>
   - <ProfileEmailAddress>
      <address>darlenebean@rr.com</address>
      <is_auto_import>false</is_auto_import>
      <is_confirmed>true</is_confirmed>
      <is_primary>true</is_primary>
      <is_auto_inbox_eligible>false</is_auto_inbox_eligible>
     </ProfileEmailAddress>
    </ProfileEmailAddresses>
    <is_client>true</is_client>
    <is_pro>false</is_pro>
    <screen_name>dbean</screen_name>
    <public_display_name>Darlene Bean</public_display_name>
    <profile_url>people/dbean</profile_url>
    <home_city>Ashland, KY</home_city>
  </Profile>
  <page_num>1</page_num>
  <page_size>500</page_size>
  <max_page>1</max_page>
</Response>
Avatar of zc2
zc2
Flag of United States of America image

Check if the document loaded properly by inserting the following lines.
If xdDoc.parseError.errorCode <> 0 Then
     Response.Write "error: " & xdDoc.parseError.reason & " in " & xdDoc.parseError.line & ":" & xdDoc.parseError.linepos
end if

Open in new window

Everything else looks fine, except one typo ( vprofileref = ojbItem.Attributes.getNamedItem("profile_ref").value)
SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Overthere
Overthere

ASKER

Got it!  Thanks to both of you!
You're welcome.