Solved

XML in Classic ASP

Posted on 2013-01-21
5
709 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 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

Is Your DevOps Pipeline Leaking?

Is your CI/CD pipeline a hodge-podge of randomly connected tools? You’ve likely got a tool to fix one problem & then a different tool to fix another, resulting in a cluster of tools with overlapping functionality. Learn how to optimize your pipeline with Gartner's recommendations

Question has a verified solution.

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

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

734 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