I have a problem with data ( soap XML) from a response from a Web Server . This is the server's response :
<xsd:hotel xsd:id="50280829" xsd:name="Villa D'Amato" xsd:lastUpdated="2016-07-28T20:33:00.786+03:00">
<xsd:room xsd:seqNo="0" xsd:id="2445883190" xsd:specialOffer="false" xsd:price="127.14" xsd:visaSupport="false">
<xsd:boardType xsd:groupId="30309841" xsd:groupName="Breakfast" xsd1:id="2359298" xsd1:name="Breakfast" xsd1:nameEn="Breakfast" xmlns:xsd1="http://types.ws.hotelston.com/xsd"/>
<xsd:roomType xsd1:id="54308004" xsd:hotelstonName="Superior Room Double Or Twin - Double Bed" xsd1:name="Superior Double or Twin Room (1 Double Bed)" xsd1:nameEn="Superior Double or Twin Room (1 Double Bed)" xmlns:xsd1="http://types.ws.hotelston.com/xsd"/>
<xsd:specifficSpecialOffer xsd1:type="PACKAGE_RATE" xmlns:xsd1="http://types.ws.hotelston.com/xsd"/>
</xsd:room>
<xsd:room xsd:seqNo="0" xsd:id="2445883190" xsd:specialOffer="false" xsd:price="127.14" xsd:visaSupport="false">
<xsd:boardType xsd:groupId="30309841" xsd:groupName="Breakfast" xsd1:id="2359298" xsd1:name="Breakfast" xsd1:nameEn="Breakfast" xmlns:xsd1="http://types.ws.hotelston.com/xsd"/>
<xsd:roomType xsd1:id="54308001" xsd:hotelstonName="Superior Room Double Or Twin" xsd1:name="Superior Double or Twin Room (2 Twin Beds)" xsd1:nameEn="Superior Double or Twin Room (2 Twin Beds)" xmlns:xsd1="http://types.ws.hotelston.com/xsd"/>
<xsd:specifficSpecialOffer xsd1:type="PACKAGE_RATE" xmlns:xsd1="http://types.ws.hotelston.com/xsd"/>
</xsd:room>
<xsd:room xsd:seqNo="0" xsd:id="2445883057" xsd:specialOffer="false" xsd:price="129.76" xsd:visaSupport="false">
<xsd:boardType xsd:groupId="30309841" xsd:groupName="Breakfast" xsd1:id="30769205" xsd1:name="English Breakfast" xsd1:nameEn="English Breakfast" xmlns:xsd1="http://types.ws.hotelston.com/xsd"/>
<xsd:roomType xsd1:id="52656547" xsd:hotelstonName="Superior Room Double Or Twin" xsd1:name="Superior Double or Twin Room" xsd1:nameEn="Superior Double or Twin Room" xmlns:xsd1="http://types.ws.hotelston.com/xsd"/>
</xsd:room>
<xsd:room xsd:seqNo="0" xsd:id="2445883059" xsd:specialOffer="false" xsd:price="132.00" xsd:visaSupport="false">
<xsd:boardType xsd:groupId="30309844" xsd:groupName="Room Only" xsd1:id="2359299" xsd1:name="Room Only" xsd1:nameEn="Room Only" xmlns:xsd1="http://types.ws.hotelston.com/xsd"/>
<xsd:roomType xsd1:id="53337950" xsd:hotelstonName="Superior Room Double Or Twin - Double Bed" xsd1:name="Superior Double or Twin Room - 1 double bed" xsd1:nameEn="Superior Double or Twin Room - 1 double bed" xmlns:xsd1="http://types.ws.hotelston.com/xsd"/>
</xsd:room>
<xsd:room xsd:seqNo="0" xsd:id="2445883192" xsd:specialOffer="false" xsd:price="137.74" xsd:visaSupport="false">
<xsd:boardType xsd:groupId="30309841" xsd:groupName="Breakfast" xsd1:id="2359298" xsd1:name="Breakfast" xsd1:nameEn="Breakfast" xmlns:xsd1="http://types.ws.hotelston.com/xsd"/>
<xsd:roomType xsd1:id="54308002" xsd:hotelstonName="Deluxe Room Double Or Twin - Double Bed" xsd1:name="Deluxe Double or Twin Room (1 Double Bed)" xsd1:nameEn="Deluxe Double or Twin Room (1 Double Bed)" xmlns:xsd1="http://types.ws.hotelston.com/xsd"/>
<xsd:specifficSpecialOffer xsd1:type="PACKAGE_RATE" xmlns:xsd1="http://types.ws.hotelston.com/xsd"/>
</xsd:room>
<xsd:room xsd:seqNo="0" xsd:id="2445883192" xsd:specialOffer="false" xsd:price="137.74" xsd:visaSupport="false">
<xsd:boardType xsd:groupId="30309841" xsd:groupName="Breakfast" xsd1:id="2359298" xsd1:name="Breakfast" xsd1:nameEn="Breakfast" xmlns:xsd1="http://types.ws.hotelston.com/xsd"/>
<xsd:roomType xsd1:id="54308003" xsd:hotelstonName="Deluxe Room Double Or Twin" xsd1:name="Deluxe Double or Twin Room (2 Twin Beds)" xsd1:nameEn="Deluxe Double or Twin Room (2 Twin Beds)" xmlns:xsd1="http://types.ws.hotelston.com/xsd"/>
<xsd:specifficSpecialOffer xsd1:type="PACKAGE_RATE" xmlns:xsd1="http://types.ws.hotelston.com/xsd"/>
</xsd:room>
<xsd:room xsd:seqNo="0" xsd:id="2445883060" xsd:specialOffer="false" xsd:price="140.58" xsd:visaSupport="false">
<xsd:boardType xsd:groupId="30309841" xsd:groupName="Breakfast" xsd1:id="30769205" xsd1:name="English Breakfast" xsd1:nameEn="English Breakfast" xmlns:xsd1="http://types.ws.hotelston.com/xsd"/>
<xsd:roomType xsd1:id="55809087" xsd:hotelstonName="Deluxe Room Double Or Twin" xsd1:name="Deluxe Double or Twin Room" xsd1:nameEn="Deluxe Double or Twin Room" xmlns:xsd1="http://types.ws.hotelston.com/xsd"/>
</xsd:room>
<xsd:room xsd:seqNo="0" xsd:id="2445883061" xsd:specialOffer="false" xsd:price="142.80" xsd:visaSupport="false">
<xsd:boardType xsd:groupId="30309844" xsd:groupName="Room Only" xsd1:id="2359299" xsd1:name="Room Only" xsd1:nameEn="Room Only" xmlns:xsd1="http://types.ws.hotelston.com/xsd"/>
<xsd:roomType xsd1:id="53338038" xsd:hotelstonName="Deluxe Room Double Or Twin - Double Bed" xsd1:name="Deluxe Double or Twin Room - 1 double bed" xsd1:nameEn="Deluxe Double or Twin Room - 1 double bed" xmlns:xsd1="http://types.ws.hotelston.com/xsd"/>
</xsd:room>
<xsd:room xsd:seqNo="0" xsd:id="2445883948" xsd:specialOffer="false" xsd:price="145.20" xsd:visaSupport="false">
<xsd:boardType xsd:groupId="30309841" xsd:groupName="Breakfast" xsd1:id="30769205" xsd1:name="English Breakfast" xsd1:nameEn="English Breakfast" xmlns:xsd1="http://types.ws.hotelston.com/xsd"/>
<xsd:roomType xsd1:id="52625987" xsd:hotelstonName="Room Double" xsd1:name="Double Room" xsd1:nameEn="Double Room" xmlns:xsd1="http://types.ws.hotelston.com/xsd"/>
</xsd:room>
<xsd:room xsd:seqNo="0" xsd:id="2445883949" xsd:specialOffer="false" xsd:price="145.20" xsd:visaSupport="false">
<xsd:boardType xsd:groupId="30309841" xsd:groupName="Breakfast" xsd1:id="30769205" xsd1:name="English Breakfast" xsd1:nameEn="English Breakfast" xmlns:xsd1="http://types.ws.hotelston.com/xsd"/>
<xsd:roomType xsd1:id="52625978" xsd:hotelstonName="Room Twin" xsd1:name="Twin Room" xsd1:nameEn="Twin Room" xmlns:xsd1="http://types.ws.hotelston.com/xsd"/>
</xsd:room>
<xsd:room xsd:seqNo="0" xsd:id="2445883474" xsd:specialOffer="false" xsd:price="175.22" xsd:visaSupport="false">
<xsd:boardType xsd:groupId="30309841" xsd:groupName="Breakfast" xsd1:id="2359298" xsd1:name="Breakfast" xsd1:nameEn="Breakfast" xmlns:xsd1="http://types.ws.hotelston.com/xsd"/>
<xsd:roomType xsd1:id="56172839" xsd:hotelstonName="Standard Double Or Twin" xsd1:name="Double or twin standard" xsd1:nameEn="Double or twin standard" xmlns:xsd1="http://types.ws.hotelston.com/xsd"/>
</xsd:room>
<xsd:room xsd:seqNo="0" xsd:id="2445882979" xsd:specialOffer="false" xsd:price="233.07" xsd:visaSupport="false">
<xsd:boardType xsd:groupId="30309843" xsd:groupName="Half Board" xsd1:id="50000721" xsd1:name="Cold Buffet Half Board" xsd1:nameEn="Cold Buffet Half Board" xmlns:xsd1="http://types.ws.hotelston.com/xsd"/>
<xsd:roomType xsd1:id="50281796" xsd:hotelstonName="Standard Room" xsd1:name="Standard Room" xsd1:nameEn="Standard Room" xmlns:xsd1="http://types.ws.hotelston.com/xsd"/>
</xsd:room>
<xsd:room xsd:seqNo="0" xsd:id="2445883063" xsd:specialOffer="false" xsd:price="309.60" xsd:visaSupport="false">
<xsd:boardType xsd:groupId="30309842" xsd:groupName="Full Board" xsd1:id="3244032" xsd1:name="Full Board" xsd1:nameEn="Full Board" xmlns:xsd1="http://types.ws.hotelston.com/xsd"/>
<xsd:roomType xsd1:id="52679712" xsd:hotelstonName="Standard Room" xsd1:name="Standard Room" xsd1:nameEn="Standard Room" xmlns:xsd1="http://types.ws.hotelston.com/xsd"/>
</xsd:room>
</xsd:hotel>
The problem occurs when I try to derive the value of the tag:
<xsd:specifficSpecialOffer xsd1:type="PACKAGE_RATE" xmlns:xsd1="http://types.ws.hotelston.com/xsd"/>
In fact if you comment this line of code everything works fine. I tried to isolate totally abandons line trying to take the value only if the node exists in this way:
if($specialOffer==null) {
$tipo_offerta="";
} else {
$tipo_offerta= $specialOffer[0]->getAttribute('xsd1:type');
}
but unfortunately it still does not work! I understand that the problem happens because this tag is not present on all nodes of the rooms. Could someone explain why? How could I solve this problem?
$specialOffer
is a node of response
And thanks to all
Solution:
if($specialOffer==NULL){
$tipo_offerta="";
} else {
$tipo_offerta= $specialOffer[0]->getAttribute('xsd1:type');
}
When to check the existence or not of the node I forgot to add the index to the array
$specialOffer[0]
I used the 0 and I did not use a counter as it is the only node.