Jump to content

Recommended Posts

Hi All,

 

I am currently having a codign problem with some xml code. i have a load of xml that is automatically supplied and 90% of it is in a very easy to use format,

the problem comes in the form of 1 xml tag which can be found mulitple time but differentiated by the attribute of the tag, for example:

<SupplementPrice number="1">5.00</SupplementPrice>

<SupplementPrice number="2">10.00</SupplementPrice>

 

My question is how can i get the value out of each of the tags and put into a normal variable - not an array.

eg $s1 = <SupplementPrice number="1">->value

$s2 = <SupplementPrice number="2">->value

 

I know you can get the attribute value and can get the actual value of the tag but cant for the life of me figure out how to do this lol

 

Thanks in advance

Link to comment
https://forums.phpfreaks.com/topic/203057-xml-attributes-problem/
Share on other sites

they are not in an array. At present the XML data is passed into an array ($db) which is then inturn passed into a function that inserts the data into a Database. The data base function puts all the data in the array $db and insert it into the database.

 

to make life real easy i wanted to take the supplementprice tag and have all 8 of them as single var's so that they can also go into the array that goes to the DB as the $db array, for forexample i need them to go into the array like this:

$db = array ('s1' => $s1, 's2' => $s2);

 

at present the array is made like this:

$rooms = $tours->Tour[$i]->Rooms;
			if(count($rooms->Room)>0){
				for($b=0; $b<count($rooms->Room); $b++){
					//need to add supplements

					$roomdata = array('Code' => $rooms->Room[$b]->RoomCode, 'Availability' => $rooms->Room[$b]->RoomAvailability, 'Name' => $rooms->Room[$b]->RoomName, 'MaxOccupance' => $rooms->Room{$b}->MaxOccupancy, 'SupplierID' => $rooms->Room[$b]->HotelCode, 'TourID' => $tours->Tour[$i]->TourID);

					$hoteldata = array('Code' => $rooms->Room[$b]->HotelCode, 'Name' => $rooms->Room[$b]->HotelName, 'Type'=> 'Hotel');//supplier hotel data
					}
				}

 

the suppliments are annoying as they arnt in their own tag tree, <supplements><s1/><s2/></supplements>, which would make this so much easier lol.

 

I really need to be able to extract the value of each supplimentPrice but assign the to variables based on the attribute 'number' of the supplement tag - if that makes sense..

 

what would be real nice is to just add them straight to the array: $db = array('s1' => $rooms->Room[$b]->SupplementPrice['number']->value); but im pretty sure that cant be done..

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.