Jump to content

xml data


teknojunkey

Recommended Posts

Hi, what is the best method for extracting information from xml there seems to be many different methods...

here is the xml ...

SimpleXMLElement Object
(
    [@attributes] => Array
        (
            [method] => getshipcontent
            [success] => Y
        )

    [errors] => SimpleXMLElement Object
        (
            [0] => 
  
        )

    [request] => SimpleXMLElement Object
        (
            [auth] => SimpleXMLElement Object
                (
                    [@attributes] => Array
                        (
                            [password] => test
                            [username] => test
                        )

                )

            [method] => SimpleXMLElement Object
                (
                    [@attributes] => Array
                        (
                            [action] => getshipcontent
                            [shipid] => 453
                            [sitename] => www.mysite.co.uk
                        )

                )

        )

    [results] => SimpleXMLElement Object
        (
            [ship] => SimpleXMLElement Object
                (
                    [@attributes] => Array
                        (
                            [adultsonly] => N
                            [codes] => 
                            [cruiseline] => African Safari Club
                            [description] => From the moment you enter at reception, you will be assured a warm welcome and friendly smile from all staff on board. Facilities include a restaurant offering excellent views of the scenery as you pass by, two small gift shops, a large lounge with a bar and a laundry service. There is also a doctor available 24 hours a day. For your peace of mind, make sure you ask reception for a safety deposit box, which is available free of charge. Enjoy a cooling dip in the small swimming pool and relax with a refreshing drink at the pool bar. You can also be pampered by taking a massage in a secluded open-air area on deck. There is also table football and table tennis.  Choose from a wide selection of items at the hot and cold buffet, whilst lunch and dinner are either buffet or waiter service. Enjoy a cabin service where you can purchase drinks of your choice between 0900 and 2300 hours. Evening entertainment includes occasional dancing and theme nights complete with belly-dancers.  
                            [hidden] => N
                            [id] => 453
                            [launched] => 1989-01-01
                            [length] => 209
                            [lineid] => 6
                            [name] => M.S. Fleurette
                            [niceurl] => african-safari-club/ms-fleurette
                            [occupancy] => 93
                            [ownerid] => system
                            [rating] => 4
                            [starrating] => 4
                            [supercedes] => 
                            [tonnage] => 1170
                            [totalcrew] => 0
                        )

I want to display  [cruiseline] and [description]  as html

thanks[/code]

Link to comment
Share on other sites

What you have shown us is not xml, its a print_r of an SimpleXMLElement Object. It is quite simple to reference object properties using ->

 

So that would be....

 

echo $xml->results->ship->cruiseline;
echo $xml->results->ship->description;

Link to comment
Share on other sites

thanks for your help and clarification...

 

I tried this ..

 

	curl_setopt( $chgs, CURLOPT_RETURNTRANSFER, 1 ); // return into a variable

curl_setopt($chgs, CURLOPT_TIMEOUT, 60);

curl_setopt( $chgs, CURLOPT_HTTPHEADER, $header ); // headers from above

$tmpgs = curl_exec( $chgs ); // runs the post

curl_close($chgs); 



$doc = simplexml_load_string($tmpgs);
echo $doc->results->ship->cruiseline;

//print_r ($doc);

 

only print_r seems to show results, echo displayed nothing

 

thanks

Link to comment
Share on other sites

Hi thanks again .. here is the xml ... from

print_r ($tmpgs);

 

<?xml version="1.0"?>
<response method="getshipcontent" success="Y">
  <errors>
  </errors>
  <request>
    <auth password="test" username="test" />
    <method action="getshipcontent" shipid="16" sitename="www.mysite.co.uk" />
  </request>

  <results>
    <ship adultsonly="N" code="" cruiseline="African Safari Club" description="M.S. Royal Star is fully stabilised and air-conditioned throughout and is ideal for cruising the islands of the Indian Ocean, as she is able to cruise close to shores and visit intriguing ports often inaccessible to larger ships. More importantly, with so few passengers there is no danger of overwhelming the character and often delicate ecosystem of the islands we visit, thus preserving what one has travelled to experience. Conditions permitting, the bridge is often open to passengers whilst at sea, which typifies the informality and similarly, the dress code is casual most evenings, although there will be one or two occasions when gentlemen will be expected to wear a jacket and tie.

" hidden="N" id="16" launched="1956-01-12" length="367" lineid="6" name="M.S.Royal Star" niceurl="african-safari-club/msroyal-star" occupancy="200" ownerid="system" rating="2" starrating="2" supercedes="" tonnage="5600" totalcrew="137">
      <cabintypes>
        <cabintype cabincode="1" cabintype="suite" caption="" description="All cabins have a private shower and wc, air conditioning, an internal telephone, taped music, a safe and adequate storage space. The majority are outside with a port-hole or window. However, port holes on Caribbean deck may be covered during adverse weather conditions.

Most of the suites have two bathrooms, mini bar and hair dryer.

" id="2044" imageurl="http://imageserver.traveltek.net/cruisepics/local_cabinimages/1243430599.jpg" name="President Suite(Outside)" smallimageurl="http://imageserver.traveltek.net/cruisepics/local_cabinimages_small/1243430599.jpg" />
        <cabintype cabincode="2" cabintype="suite" caption="" description="All cabins have a private shower and wc, air conditioning, an internal telephone, taped music, a safe and adequate storage space. The majority are outside with a port-hole or window. However, port holes on Caribbean deck may be covered during adverse weather conditions.

Most of the suites have two bathrooms, mini bar and hair dryer.

" id="2045" name="Honeymoon Suite(Outside)" />
        <cabintype cabincode="3" cabintype="suite" caption="" description="All cabins have a private shower and wc, air conditioning, an internal telephone, taped music, a safe and adequate storage space. The majority are outside with a port-hole or window. However, port holes on Caribbean deck may be covered during adverse weather conditions.

Most of the suites have two bathrooms, mini bar and hair dryer.

" id="2046" imageurl="http://imageserver.traveltek.net/cruisepics/local_cabinimages/1228299808.jpg" name="Superior Suite(Outside)" smallimageurl="http://imageserver.traveltek.net/cruisepics/local_cabinimages_small/1228299808.jpg" />
        <cabintype cabincode="4" cabintype="cabin" caption="Deluxe Cabin (4)" description="All cabins have a private shower and wc, air conditioning, an internal telephone, taped music, a safe and adequate storage space. The majority are outside with a port-hole or window. However, port holes on Caribbean deck may be covered during adverse weather conditions.

Most of the suites have two bathrooms, mini bar and hair dryer.

" id="2047" imageurl="http://imageserver.traveltek.net/cruisepics/local_cabinimages/1220965161.jpg" name="Deluxe Cabin" smallimageurl="http://imageserver.traveltek.net/cruisepics/local_cabinimages_small/1220965161.jpg" />
        <cabintype cabincode="A" cabintype="cabin" caption="" description="All cabins have a private shower and wc, air conditioning, an internal telephone, taped music, a safe and adequate storage space. The majority are outside with a port-hole or window. However, port holes on Caribbean deck may be covered during adverse weather conditions.

Most of the suites have two bathrooms, mini bar and hair dryer.

" id="2039" imageurl="http://imageserver.traveltek.net/cruisepics/local_cabinimages/1228299715.jpg" name="Standard Cabin" smallimageurl="http://imageserver.traveltek.net/cruisepics/local_cabinimages_small/1228299715.jpg" />
        <cabintype cabincode="B" cabintype="cabin" caption="" description="All cabins have a private shower and wc, air conditioning, an internal telephone, taped music, a safe and adequate storage space. The majority are outside with a port-hole or window. However, port holes on Caribbean deck may be covered during adverse weather conditions.

Most of the suites have two bathrooms, mini bar and hair dryer.

" id="2040" imageurl="http://imageserver.traveltek.net/cruisepics/local_cabinimages/1228299697.jpg" name="Standard Cabin" smallimageurl="http://imageserver.traveltek.net/cruisepics/local_cabinimages_small/1228299697.jpg" />

        <cabintype cabincode="B" cabintype="outside" caption="" description="All cabins have a private shower and wc, air conditioning, an internal telephone, taped music, a safe and adequate storage space. The majority are outside with a port-hole or window. However, port holes on Caribbean deck may be covered during adverse weather conditions.

Most of the suites have two bathrooms, mini bar and hair dryer.

" id="2041" imageurl="http://imageserver.traveltek.net/cruisepics/local_cabinimages/1228299678.jpg" name="Standard Cabin" smallimageurl="http://imageserver.traveltek.net/cruisepics/local_cabinimages_small/1228299678.jpg" />
        <cabintype cabincode="C" cabintype="outside" caption="" description="All cabins have a private shower and wc, air conditioning, an internal telephone, taped music, a safe and adequate storage space. The majority are outside with a port-hole or window. However, port holes on Caribbean deck may be covered during adverse weather conditions.

Most of the suites have two bathrooms, mini bar and hair dryer.

" id="2042" imageurl="http://imageserver.traveltek.net/cruisepics/local_cabinimages/1228299314.jpg" name="Standard Cabin" smallimageurl="http://imageserver.traveltek.net/cruisepics/local_cabinimages_small/1228299314.jpg" />
        <cabintype cabincode="D" cabintype="outside" caption="" description="All cabins have a private shower and wc, air conditioning, an internal telephone, taped music, a safe and adequate storage space. The majority are outside with a port-hole or window. However, port holes on Caribbean deck may be covered during adverse weather conditions.

Most of the suites have two bathrooms, mini bar and hair dryer.

" id="2043" imageurl="http://imageserver.traveltek.net/cruisepics/local_cabinimages/1228299293.jpg" name="Standard Cabin" smallimageurl="http://imageserver.traveltek.net/cruisepics/local_cabinimages_small/1228299293.jpg" />
        <cabintype cabincode="E" cabintype="inside" caption="" description="All cabins have a private shower and wc, air conditioning, an internal telephone, taped music, a safe and adequate storage space. The majority are outside with a port-hole or window. However, port holes on Caribbean deck may be covered during adverse weather conditions.

Most of the suites have two bathrooms, mini bar and hair dryer.

" id="2048" imageurl="http://imageserver.traveltek.net/cruisepics/local_cabinimages/1243430769.jpg" name="Inside Cabin" smallimageurl="http://imageserver.traveltek.net/cruisepics/local_cabinimages_small/1243430769.jpg" />
      </cabintypes>
      <facilities>
        <facility category="Food and Drink" categoryid="1">
          <item categoryid="1" description="" facilityid="187" facilitytypeid="187" name="Buffet" quantity="" />
          <item categoryid="1" description="" facilityid="160" facilitytypeid="160" name="Lounge" quantity="" />

          <item categoryid="1" description="" facilityid="196" facilitytypeid="196" name="Piano Bar" quantity="" />
          <item categoryid="1" description="" facilityid="46" facilitytypeid="46" name="Restaurant" quantity="" />
        </facility>
        <facility category="Other" categoryid="7">
          <item categoryid="7" description="" facilityid="197" facilitytypeid="197" name="Boutique" quantity="" />
          <item categoryid="7" description="" facilityid="1027" facilitytypeid="1027" name="Elevator" quantity="" />
          <item categoryid="7" description="" facilityid="220" facilitytypeid="220" name="Laundry Service" quantity="" />
          <item categoryid="7" description="" facilityid="175" facilitytypeid="175" name="Medical Centre" quantity="" />
          <item categoryid="7" description="" facilityid="210" facilitytypeid="210" name="Shopping Gallery" quantity="" />

          <item categoryid="7" description="" facilityid="223" facilitytypeid="223" name="Shore Excursion Office" quantity="" />
        </facility>
        <facility category="Relaxation" categoryid="3">
          <item categoryid="3" description="" facilityid="192" facilitytypeid="192" name="Beauty Salon" quantity="" />
          <item categoryid="3" description="" facilityid="219" facilitytypeid="219" name="Massage" quantity="" />
          <item categoryid="3" description="" facilityid="188" facilitytypeid="188" name="Sauna" quantity="" />
          <item categoryid="3" description="" facilityid="225" facilitytypeid="225" name="Sun Deck" quantity="" />
          <item categoryid="3" description="" facilityid="155" facilitytypeid="155" name="Swimming Pool" quantity="" />
        </facility>

        <facility category="Entertainment" categoryid="2">
          <item categoryid="2" description="" facilityid="163" facilitytypeid="163" name="Board/card games" quantity="" />
          <item categoryid="2" description="" facilityid="156" facilitytypeid="156" name="Casino" quantity="" />
        </facility>
        <facility category="Recreational" categoryid="5">
          <item categoryid="5" description="" facilityid="64" facilitytypeid="64" name="Library" quantity="" />
          <item categoryid="5" description="" facilityid="44" facilitytypeid="44" name="Outdoor Pool" quantity="" />
        </facility>
        <facility category="Fitness" categoryid="4">

          <item categoryid="4" description="" facilityid="148" facilitytypeid="148" name="Gym" quantity="" />
          <item categoryid="4" description="" facilityid="882" facilitytypeid="882" name="Sports Deck" quantity="" />
        </facility>
      </facilities>
      <images>
        <image caption="M.S.Royal Star " default="Y" id="9408" imageurl="http://imageserver.traveltek.net/cruisepics/local_shipimages_large/1243429202.jpg" ownerid="system" smallimageurl="http://imageserver.traveltek.net/cruisepics/local_shipimages_small/1243429202.jpg" type="photo" />
        <image caption="Casino" default="N" id="9427" imageurl="http://imageserver.traveltek.net/cruisepics/local_shipimages_large/1243429794.jpg" ownerid="system" smallimageurl="http://imageserver.traveltek.net/cruisepics/local_shipimages_small/1243429794.jpg" type="photo" />
        <image caption="Buffet" default="N" id="9421" imageurl="http://imageserver.traveltek.net/cruisepics/local_shipimages_large/1243429702.jpg" ownerid="system" smallimageurl="http://imageserver.traveltek.net/cruisepics/local_shipimages_small/1243429702.jpg" type="photo" />
        <image caption="Belvedere Restaurant" default="N" id="9414" imageurl="http://imageserver.traveltek.net/cruisepics/local_shipimages_large/1243429602.jpg" ownerid="system" smallimageurl="http://imageserver.traveltek.net/cruisepics/local_shipimages_small/1243429602.jpg" type="photo" />

        <image caption="Entertainment " default="N" id="9444" imageurl="http://imageserver.traveltek.net/cruisepics/local_shipimages_large/1243430158.jpg" ownerid="system" smallimageurl="http://imageserver.traveltek.net/cruisepics/local_shipimages_small/1243430158.jpg" type="photo" />
        <image caption="Back of Ship" default="N" id="9412" imageurl="http://imageserver.traveltek.net/cruisepics/local_shipimages_large/1243429620.jpg" ownerid="system" smallimageurl="http://imageserver.traveltek.net/cruisepics/local_shipimages_small/1243429620.jpg" type="photo" />
        <image caption="Cocktails" default="N" id="9429" imageurl="http://imageserver.traveltek.net/cruisepics/local_shipimages_large/1243429880.jpg" ownerid="system" smallimageurl="http://imageserver.traveltek.net/cruisepics/local_shipimages_small/1243429880.jpg" type="photo" />
        <image caption="Chefs" default="N" id="9431" imageurl="http://imageserver.traveltek.net/cruisepics/local_shipimages_large/1243429852.jpg" ownerid="system" smallimageurl="http://imageserver.traveltek.net/cruisepics/local_shipimages_small/1243429852.jpg" type="photo" />
        <image caption="Dining" default="N" id="9433" imageurl="http://imageserver.traveltek.net/cruisepics/local_shipimages_large/1243429875.jpg" ownerid="system" smallimageurl="http://imageserver.traveltek.net/cruisepics/local_shipimages_small/1243429875.jpg" type="photo" />
        <image caption="Crew" default="N" id="9436" imageurl="http://imageserver.traveltek.net/cruisepics/local_shipimages_large/1243429920.jpg" ownerid="system" smallimageurl="http://imageserver.traveltek.net/cruisepics/local_shipimages_small/1243429920.jpg" type="photo" />
        <image caption="Drinks on Deck" default="N" id="9441" imageurl="http://imageserver.traveltek.net/cruisepics/local_shipimages_large/1243430065.jpg" ownerid="system" smallimageurl="http://imageserver.traveltek.net/cruisepics/local_shipimages_small/1243430065.jpg" type="photo" />
        <image caption="Drinks on Deck 2 " default="N" id="9443" imageurl="http://imageserver.traveltek.net/cruisepics/local_shipimages_large/1243430085.jpg" ownerid="system" smallimageurl="http://imageserver.traveltek.net/cruisepics/local_shipimages_small/1243430085.jpg" type="photo" />
        <image caption="Entertainment 2" default="N" id="9445" imageurl="http://imageserver.traveltek.net/cruisepics/local_shipimages_large/1243430161.jpg" ownerid="system" smallimageurl="http://imageserver.traveltek.net/cruisepics/local_shipimages_small/1243430161.jpg" type="photo" />

        <image caption="Relaxing on Deck " default="N" id="9447" imageurl="http://imageserver.traveltek.net/cruisepics/local_shipimages_large/1243430153.jpg" ownerid="system" smallimageurl="http://imageserver.traveltek.net/cruisepics/local_shipimages_small/1243430153.jpg" type="photo" />
        <image caption="On the Bridge " default="N" id="9450" imageurl="http://imageserver.traveltek.net/cruisepics/local_shipimages_large/1243430201.jpg" ownerid="system" smallimageurl="http://imageserver.traveltek.net/cruisepics/local_shipimages_small/1243430201.jpg" type="photo" />
        <image caption="Starlight Piano Bar" default="N" id="9453" imageurl="http://imageserver.traveltek.net/cruisepics/local_shipimages_large/1243430346.jpg" ownerid="system" smallimageurl="http://imageserver.traveltek.net/cruisepics/local_shipimages_small/1243430346.jpg" type="photo" />
        <image caption="View On Deck" default="N" id="9456" imageurl="http://imageserver.traveltek.net/cruisepics/local_shipimages_large/1243430355.jpg" ownerid="system" smallimageurl="http://imageserver.traveltek.net/cruisepics/local_shipimages_small/1243430355.jpg" type="photo" />
        <image caption="Tender Boat" default="N" id="9455" imageurl="http://imageserver.traveltek.net/cruisepics/local_shipimages_large/1243430322.jpg" ownerid="system" smallimageurl="http://imageserver.traveltek.net/cruisepics/local_shipimages_small/1243430322.jpg" type="photo" />
        <image caption="View On Deck 2 " default="N" id="9459" imageurl="http://imageserver.traveltek.net/cruisepics/local_shipimages_large/1243430381.jpg" ownerid="system" smallimageurl="http://imageserver.traveltek.net/cruisepics/local_shipimages_small/1243430381.jpg" type="photo" />
        <image caption="View On Deck 3" default="N" id="9458" imageurl="http://imageserver.traveltek.net/cruisepics/local_shipimages_large/1243430369.jpg" ownerid="system" smallimageurl="http://imageserver.traveltek.net/cruisepics/local_shipimages_small/1243430369.jpg" type="photo" />
        <image caption="Ship 2" default="N" id="9460" imageurl="http://imageserver.traveltek.net/cruisepics/local_shipimages_large/1243430497.jpg" ownerid="system" smallimageurl="http://imageserver.traveltek.net/cruisepics/local_shipimages_small/1243430497.jpg" type="photo" />
        <image caption="Ship 3" default="N" id="9461" imageurl="http://imageserver.traveltek.net/cruisepics/local_shipimages_large/1243430452.jpg" ownerid="system" smallimageurl="http://imageserver.traveltek.net/cruisepics/local_shipimages_small/1243430452.jpg" type="photo" />

        <image caption="Ship 4 " default="N" id="9464" imageurl="http://imageserver.traveltek.net/cruisepics/local_shipimages_large/1243430536.jpg" ownerid="system" smallimageurl="http://imageserver.traveltek.net/cruisepics/local_shipimages_small/1243430536.jpg" type="photo" />
      </images>
    </ship>
  </results>
</response>
</pre>

 

any help or advice is appreciated :)

 

Link to comment
Share on other sites

You were missing the 'response' node.  Also, you have '' at the bottom of your xml, is that supposed to be there?

 

   $doc = simplexml_load_string($tmpgs);
   $docResults = $doc->response->results->ship->cruiseline;

   print_r ($docResults);

Link to comment
Share on other sites

thanks, the </pre> was part of the html, a sloppy copy and paste was to blame.

 

i tried

$docResults = $doc->response->results->ship->cruiseline;

there was nothing returned

 

i tried

$docResults = $doc->response;

i got this

SimpleXMLElement Object
(
)

 

i dont understand whats going on

thanks

Link to comment
Share on other sites

I kind of figured it out, i used this ... but i still can access the cruiseline data

 

$docResults = $doc->results->ship;

 

I cant specify any of the [@attributes] array

 

    [results] => SimpleXMLElement Object
        (
            [ship] => SimpleXMLElement Object
                (
                    [@attributes] => Array
                        (
                            [adultsonly] => N
                            [code] => 
                            [cruiseline] => African Safari Club
                            [description] => M.S. Royal Star is fully stabilised and air-conditioned throughout and is ideal for cruising the islands of the Indian Ocean, as she is able to cruise close to shores and visit intriguing ports often inaccessible to larger ships. More importantly, with so few passengers there is no danger of overwhelming the character and often delicate ecosystem of the islands we visit, thus preserving what one has travelled to experience. Conditions permitting, the bridge is often open to passengers whilst at sea, which typifies the informality and similarly, the dress code is casual most evenings, although there will be one or two occasions when gentlemen will be expected to wear a jacket and tie.  
                            [hidden] => N

 

 

i tried

 

$docResults = $doc->results->ship->attributes->cruiseline;

 

how can i access the elements in the  [@attributes] => Array

 

thanks

 

 

Link to comment
Share on other sites

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.