Solved

Parsing XML VBScript

Posted on 2013-01-07
2
554 Views
Last Modified: 2013-01-08
Hello,

I have an XML file which I'm trying to parse.  I get most of the data with no issues, but there is a sub array for images, which has 3 nodes, but my code isn't seperating the nodes, so I'm getting all the data in one long string - I need it seperated so I can add it to my DB...

The first part of the XML file is:
<?xml version="1.0" encoding="utf-8"?>
<result>
<HouseCode>AT-1010-04</HouseCode>
<Updated>2013-01-06T10:55:59-08:00</Updated>
<BasicInformationV3>
  <Name>Studio Wien Zentrum</Name>
  <MaxNumberOfPersons>2</MaxNumberOfPersons>
  <ExceedNumberOfBabies>0</ExceedNumberOfBabies>
  <NumberOfPets>3</NumberOfPets>
  <NumberOfStars>3</NumberOfStars>
  <DimensionM2>25</DimensionM2>
  <ZipPostalCode>1010</ZipPostalCode>
  <Country>AT</Country>
  <Region>NIE</Region>
  <CreationDate>2010-02-22</CreationDate>
  <WGS84Longitude>16.383728</WGS84Longitude>
  <WGS84Latitude>48.211055</WGS84Latitude>
  <OptionsAllowed>No</OptionsAllowed>
  <HolidayPark>at-1010-001</HolidayPark>
  <EnqeCount>6</EnqeCount>
  <EnqePoints>54</EnqePoints>
  <NumberOfBedrooms>0</NumberOfBedrooms>
  <NumberOfBathrooms>1</NumberOfBathrooms>
  <SkiArea/>
  <Brands>
    <element>
      <SequenceNumber>1</SequenceNumber>
      <Brand>BV</Brand>
    </element>
  </Brands>
</BasicInformationV3>
<MediaV1>
  <Photos>
    <Photo>
      <Tag>ExteriorSummer</Tag>
      <Height>500</Height>
      <URL>media.leisure-ict.net/photo/web/500/83583_lsr_20101213106909640392.jpg</URL>
    </Photo>
    <Photo>
      <Tag>ExteriorSummer</Tag>
      <Height>500</Height>
      <URL>media.leisure-ict.net/photo/web/500/83583_lsr_2010110252638872804.jpg</URL>
    </Photo>

Open in new window


and my code,which is within another array (of all the properties) is:
set images_list = itemAttrib.SelectNodes("MediaV1/*[starts-with(name(),'Photo')]")
    For Each i In images_list
	z = z + 1
    image = i.text
    	if image <> "" then
	imagename = right(image, (len(image) - len("http://media.leisure-ict.net/photo/web/")))
	response.Write(imagename & "<BR>")
    	end if
	response.Flush()
    next

Open in new window


And the output I get is:

t/photo/web/500/83583_lsr_20101213106909640392.jpg ExteriorSummer 500 media.leisure-ict.net/photo/web/500/83583_lsr_2010110252638872804.jpg ExteriorSummer 500 media.leisure-ict.net/photo/web/500/83583_lsr_2010110252568593389.jpg HallReception 500 media.leisure-ict.net/photo/web/500/83583_lsr_2010110252815864325.jpg LivingRoom 500 media.leisure-ict.net/photo/web/500/83583_lsr_2010110252896152910.jpg LivingRoom 500 media.leisure-ict.net/photo/web/500/83583_lsr_2010110252881510637.jpg LivingRoom 500 media.leisure-ict.net/photo/web/500/83583_lsr_2010110252850841576.jpg Kitchen 500 media.leisure-ict.net/photo/web/500/83583_lsr_2010110252865548629.jpg Kitchen 500 media.leisure-ict.net/photo/web/500/83583_lsr_2010110252914303597.jpg ParkFacilities 500 media.leisure-ict.net/photo/web/500/83583_lsr_2010110252739056371.jpg ParkFacilities 500 media.leisure-ict.net/photo/web/500/83583_lsr_2010110252765821198.jpg ParkFacilities 500 media.leisure-ict.net/photo/web/500/83583_lsr_2010110252582697238.jpg ParkFacilities 500 media.leisure-ict.net/photo/web/500/83583_lsr_2010110252779065199.jpg AreaSummer1KM 500 media.leisure-ict.net/photo/web/500/83583_lsr_2010110252517689956.jpg AreaSummer1KM 500 media.leisure-ict.net/photo/web/500/83583_lsr_2010110252697644269.jpg AreaSummer1KM 500 media.leisure-ict.net/photo/web/500/83583_lsr_2010110252601105859.jpg

Open in new window


It's also missing part of the first image filename, bu I do also want to be able t grab the description of each image, which is in the data above, but all bunched up!

Help appreciated - thanks!
0
Comment
Question by:Nico2011
2 Comments
 
LVL 20

Accepted Solution

by:
ltlbearand3 earned 500 total points
ID: 38753599
I don't know that I have enough detail, but will take a shot.  When you say you want this broken out into the different nodes for you database, do you just want this in additional variables?  Since I don't have all your code, I am not sure what you are doing with the Z Variable so I left it.  I also don't understand why you do you node select with Start with Photo as you have a node name Photos and one named Photo.  I would recommend a more clear search to find the node you expect.  The command that strips out the first part of the URL has more information that what is in your node value.  I am guessing you are just wanting the file name and I have tried to adjust for that.

Maybe try something like this:

set images_list = itemAttrib.SelectNodes("//Photo")

For Each i In images_list
	z = z + 1
	If Not i.SelectSingleNode(".//Tag") is nothing Then
		strTag = i.SelectSingleNode(".//Tag").text
		response.Write(strTag & "<BR>")
	End if
	If Not i.SelectSingleNode(".//Height") is nothing Then
		strHeight = i.SelectSingleNode(".//Height").text
		response.Write(strHeight & "<BR>")
	End if
	If Not i.SelectSingleNode(".//URL") is nothing Then
		strUrl = i.SelectSingleNode(".//URL").text
		If left(strUrl, 4) = "Http" Then
			strurl = right(strUrl, len(strUrl) - len("http://media.leisure-ict.net/photo/web/" & strHeight & "/"))
		Else
			strurl = right(strUrl, len(strUrl) - len("media.leisure-ict.net/photo/web/" & strHeight & "/"))
		End if
		response.Write(strTag & "<BR>")
	End if
	response.Flush()
next

Open in new window


-Bear
0
 

Author Closing Comment

by:Nico2011
ID: 38754156
That is PRECISELY what I needed - thank you so much Bear - works perfectly!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

895 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

16 Experts available now in Live!

Get 1:1 Help Now