Note that there are some explanatory texts on larger screens.

plurals
  1. PORead XML attributes using PHP
    primarykey
    data
    text
    <p>I m using a API to display results w.r.t to search query.</p> <p>The output will be in the form of XML, I need to parse the XML and display the result in the browser.</p> <p>The file contains many attributes from which i m not sure how to extract the results.</p> <p>Here is my code:</p> <pre><code>&lt;?xml version="1.0" ?&gt; &lt;S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"&gt; &lt;S:Body&gt; &lt;ns3:tourDetailsFullResponse xmlns:ns2="http://example.com/" xmlns:ns3="http://example.com/" xmlns:ns4="http://www.example.com/"&gt; &lt;ns4:MarketLocalisedTourData SellingCompanyCode="CODE1" OperatingProductCode="CODE2" MarketVariationCode="CODE3" Duration="8" Currency="USD" CatalogueCode="CODE4" TropicsBrochureCode="CODE5" BrandCode="CODE6" BookableOnline="true"&gt; &lt;ns4:TourInfo&gt; &lt;ns4:TourName&gt;London to Rome Highlights 2013&lt;/ns4:TourName&gt; &lt;ns4:Metadata&gt; &lt;ns4:TourCategories&gt; &lt;ns4:TourCategory Name="TourStyles"&gt; &lt;ns4:CategoryValue Name="European Discoveries"/&gt; &lt;/ns4:TourCategory&gt; &lt;/ns4:TourCategories&gt; &lt;ns4:Brochures&gt; &lt;ns4:Brochure Name="CostSaver 2013" Code="CODE1"/&gt; &lt;/ns4:Brochures&gt; &lt;/ns4:Metadata&gt; &lt;ns4:ContinentsVisited&gt; &lt;ns4:Continent Name="Europe" Code="EURO"/&gt; &lt;/ns4:ContinentsVisited&gt; &lt;ns4:CountriesVisited&gt; &lt;ns4:Country Name="France" Continent="EURO" Code="FR"/&gt; &lt;ns4:Country Name="United Kingdom" Continent="EURO" Code="GB"/&gt; &lt;ns4:Country Name="Italy" Continent="EURO" Code="IT"/&gt; &lt;ns4:Country Name="Switzerland" Continent="EURO" Code="CH"/&gt; &lt;/ns4:CountriesVisited&gt; &lt;ns4:LocationsVisited&gt; &lt;ns4:Location Name="Paris" Country="FR"/&gt; &lt;ns4:Location Name="Dover" Country="GB"/&gt; &lt;ns4:Location Name="London" Country="GB"/&gt; &lt;ns4:Location Name="Rome" Country="IT"/&gt; &lt;ns4:Location Name="Calais" Country="FR"/&gt; &lt;ns4:Location Name="Venice" Country="IT"/&gt; &lt;ns4:Location Name="Lucerne" Country="CH"/&gt; &lt;ns4:Location Name="Florence" Country="IT"/&gt; &lt;/ns4:LocationsVisited&gt; &lt;ns4:Description&gt;A lively journey through elegant Paris, gorgeous Lake Lucerne, charming Venice and cultural Florence, bookended by stays in London and legendary Rome. Spend a day at leisure in London and get the best views of Rome from high up in St. Peter’s Basilica before throwing a lucky coin in Trevi Fountain.&lt;/ns4:Description&gt; &lt;ns4:Assets&gt; &lt;ns4:Image Width="297" Url="http://www.example.com/imageurl" Type="map" Name="route_map" Height="297" Caption="route_map"/&gt; &lt;ns4:Image Width="600" Url="http://www.example.com/imageurl" Type="map" Name="route_map" Height="600" Caption="route_map"/&gt; &lt;ns4:Image Width="531" Url="http://www.example.com/imageurl" Type="photo" Name="primary_image" Height="531" Caption="primary_image"/&gt; &lt;ns4:Image Width="125" Url="http://www.example.com/imageurl" Type="photo" Name="primary_image" Height="125" Caption="primary_image"/&gt; &lt;/ns4:Assets&gt; ....continues </code></pre> <p>Now i want to extract the continents visited , countries visited, locations visited, itinerary, assests etc...</p> <p>I tried using simple xml like the following </p> <pre><code>$feed = "response1_full.xml"; $xml = simplexml_load_file($feed); print_r($xml); foreach($xml-&gt;LocationsVisited[0]-&gt;attributes() as $a =&gt; $b) { echo $a,'="',$b,"\"\n"; } also tried foreach($xml-&gt;TourInfo-&gt;LocationsVisited[0]-&gt;attributes() as $a =&gt; $b) { echo $a,'="',$b,"\"\n"; } </code></pre> <p>also tried all other possibilities which results in same error </p> <blockquote> <p>Fatal error: Call to a member function attributes() on a non-object in C:\xampp\htdocs\test\xmlread2.php on line 10</p> </blockquote> <p>I m searching a solution for this more than couple of days.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload