Solved

Parsing XML VBScript

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction During my participation as a VBScript contributor at Experts Exchange, one of the most common questions I come across is this: "I have a script that runs against only one computer. How can I make it run against a list of computers in …
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…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

695 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