Solved

Parsing XML VBScript

Posted on 2013-01-07
2
552 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

When it comes to writing scripts for a Client/Server computing environment it is essential to consider some way of enabling the authentication functionality within a script. This sort of consideration mainly comes into the picture when we are dealin…
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

706 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

12 Experts available now in Live!

Get 1:1 Help Now