Solved

XML in Classic ASP

Posted on 2013-01-21
5
699 Views
Last Modified: 2013-01-24
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>
0
Comment
Question by:Overthere
  • 3
5 Comments
 
LVL 18

Expert Comment

by:zc2
ID: 38803440
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)
0
 
LVL 74

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 250 total points
ID: 38803485
The only issue I see (outside of the aforementioned typo) is that you are trying to iterate over the attributes of a <Trip>, which in this case there are none. I believe the "profile_ref" you are looking for is actually for the <Invitee> element. If that be the case, then you need to change the last line from:

vprofileref = objItem.Attributes.getNamedItem("profile_ref").value

to something along the lines of:

set vprofilerefs = objItem.selectNodes("TripInvitees/Invitee/@profile_ref")

for each prof in vprofilerefs
    vprofileref = prof.value
next

Open in new window

0
 
LVL 18

Accepted Solution

by:
zc2 earned 250 total points
ID: 38803556
I agree, that was not accurate. Here's a sample code to enumerate the Profiles. May be that will be useful.
    	for each objInvitee In objItem.selectNodes("TripInvitees/Invitee")
                vprofileref = objInvitee.getAttribute("profile_ref")
        	for each objProfile In xdDoc.selectNodes("Response/Profile[@ref='" & vprofileref & "']")
                Response.Write "Profile Name = " & objProfile.selectSingleNode("public_display_name").text
        	next
       	next

Open in new window

0
 

Author Closing Comment

by:Overthere
ID: 38816868
Got it!  Thanks to both of you!
0
 
LVL 18

Expert Comment

by:zc2
ID: 38816879
You're welcome.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now