Arazmus Posted May 27, 2010 Share Posted May 27, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/203057-xml-attributes-problem/ Share on other sites More sharing options...
Adam Posted May 27, 2010 Share Posted May 27, 2010 You've written the code to parse them into an array, yeah? So on that array you could just extract them into the variables.. Although seems odd you'd want them in variables and not an array? Quote Link to comment https://forums.phpfreaks.com/topic/203057-xml-attributes-problem/#findComment-1064009 Share on other sites More sharing options...
Arazmus Posted May 27, 2010 Author Share Posted May 27, 2010 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.. Quote Link to comment https://forums.phpfreaks.com/topic/203057-xml-attributes-problem/#findComment-1064011 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.