?
Solved

XML in Classic ASP

Posted on 2013-01-21
5
Medium Priority
?
715 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 75

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 1000 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 1000 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

777 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