Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

XML in Classic ASP

Posted on 2013-01-21
5
Medium Priority
?
750 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 19

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 19

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 19

Expert Comment

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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

610 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