tarrigo
asked on
PHP and access XML Web Service
I am trying to, at least for now, make a connection to a web service using php in a web page. The information below is all I have received from the creator of the service. I am not sure how to begin. The code below is not functional, since you need membership, but wondering if there are any clues on what I need code in order to call the url using the get method so I can get the XML result.
GET /xmlsearch.asmx/SearchInve ntory?User =string&Ke y=string&P art=string &Mfg=strin g&DateCode =string&Da teCodeComp areType=st ring&MinQu antity=str ing&StockF lag=string &PricesOnl y=string&P referredVe ndorsOnly= string&Reg ion=string &SearchTyp e=string&M axResults= string&Pag eNum=strin g&Sort=str ing HTTP/1.1
Host: xmlsearch.mysite.com
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length
<?xml version="1.0" encoding="utf-8"?>
<DataSet xmlns="http://XMLSearch.mysite.com/XMLSearch">
<schema xmlns="http://www.w3.org/2001/XMLSchema">schema</schema>xm l</DataSet >
GET /xmlsearch.asmx/SearchInve
Host: xmlsearch.mysite.com
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length
<?xml version="1.0" encoding="utf-8"?>
<DataSet xmlns="http://XMLSearch.mysite.com/XMLSearch">
<schema xmlns="http://www.w3.org/2001/XMLSchema">schema</schema>xm
You can probably read from the URL with PHP file_get_contents(). When you get the XML response from the URL, please post it here and we can show you how to process it.
ASKER
I should explain overall what I am going to do. I am going to take the results of an XML web service and place it in table of database. I had accomplished this years ago in classic asp, but php has me a bit confused when it comes to the XML web service retrieval part.
So for instance, just for practice sake I read and used the code from the url you left above. The code I used was:
and it brought back the XML response of:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Edited by XMLSpy -->
<CATALOG>
<PLANT>
<COMMON>Bloodroot</COMMON>
<BOTANICAL>Sanguinaria canadensis</BOTANICAL>
<ZONE>4</ZONE>
<LIGHT>Mostly Shady</LIGHT>
<PRICE>$2.44</PRICE>
<AVAILABILITY>031599</AVAI LABILITY>
</PLANT>
<PLANT>
<COMMON>Columbine</COMMON>
<BOTANICAL>Aquilegia canadensis</BOTANICAL>
<ZONE>3</ZONE>
<LIGHT>Mostly Shady</LIGHT>
<PRICE>$9.37</PRICE>
<AVAILABILITY>030699</AVAI LABILITY>
</PLANT>
<PLANT>
<COMMON>Marsh Marigold</COMMON>
<BOTANICAL>Caltha palustris</BOTANICAL>
<ZONE>4</ZONE>
<LIGHT>Mostly Sunny</LIGHT>
<PRICE>$6.81</PRICE>
<AVAILABILITY>051799</AVAI LABILITY>
</PLANT>
<PLANT>
<COMMON>Cowslip</COMMON>
<BOTANICAL>Caltha palustris</BOTANICAL>
<ZONE>4</ZONE>
<LIGHT>Mostly Shady</LIGHT>
<PRICE>$9.90</PRICE>
<AVAILABILITY>030699</AVAI LABILITY>
</PLANT>
<PLANT>
<COMMON>Dutchman's-Breeche s</COMMON>
<BOTANICAL>Dicentra cucullaria</BOTANICAL>
<ZONE>3</ZONE>
<LIGHT>Mostly Shady</LIGHT>
<PRICE>$6.44</PRICE>
<AVAILABILITY>012099</AVAI LABILITY>
</PLANT>
<PLANT>
<COMMON>Ginger, Wild</COMMON>
<BOTANICAL>Asarum canadense</BOTANICAL>
<ZONE>3</ZONE>
<LIGHT>Mostly Shady</LIGHT>
<PRICE>$9.03</PRICE>
<AVAILABILITY>041899</AVAI LABILITY>
</PLANT>
<PLANT>
<COMMON>Hepatica</COMMON>
<BOTANICAL>Hepatica americana</BOTANICAL>
<ZONE>4</ZONE>
<LIGHT>Mostly Shady</LIGHT>
<PRICE>$4.45</PRICE>
<AVAILABILITY>012699</AVAI LABILITY>
</PLANT>
<PLANT>
<COMMON>Liverleaf</COMMON>
<BOTANICAL>Hepatica americana</BOTANICAL>
<ZONE>4</ZONE>
<LIGHT>Mostly Shady</LIGHT>
<PRICE>$3.99</PRICE>
<AVAILABILITY>010299</AVAI LABILITY>
</PLANT>
<PLANT>
<COMMON>Jack-In-The-Pulpit </COMMON>
<BOTANICAL>Arisaema triphyllum</BOTANICAL>
<ZONE>4</ZONE>
<LIGHT>Mostly Shady</LIGHT>
<PRICE>$3.23</PRICE>
<AVAILABILITY>020199</AVAI LABILITY>
</PLANT>
<PLANT>
<COMMON>Mayapple</COMMON>
<BOTANICAL>Podophyllum peltatum</BOTANICAL>
<ZONE>3</ZONE>
<LIGHT>Mostly Shady</LIGHT>
<PRICE>$2.98</PRICE>
<AVAILABILITY>060599</AVAI LABILITY>
</PLANT>
<PLANT>
<COMMON>Phlox, Woodland</COMMON>
<BOTANICAL>Phlox divaricata</BOTANICAL>
<ZONE>3</ZONE>
<LIGHT>Sun or Shade</LIGHT>
<PRICE>$2.80</PRICE>
<AVAILABILITY>012299</AVAI LABILITY>
</PLANT>
<PLANT>
<COMMON>Phlox, Blue</COMMON>
<BOTANICAL>Phlox divaricata</BOTANICAL>
<ZONE>3</ZONE>
<LIGHT>Sun or Shade</LIGHT>
<PRICE>$5.59</PRICE>
<AVAILABILITY>021699</AVAI LABILITY>
</PLANT>
<PLANT>
<COMMON>Spring-Beauty</COM MON>
<BOTANICAL>Claytonia Virginica</BOTANICAL>
<ZONE>7</ZONE>
<LIGHT>Mostly Shady</LIGHT>
<PRICE>$6.59</PRICE>
<AVAILABILITY>020199</AVAI LABILITY>
</PLANT>
<PLANT>
<COMMON>Trillium</COMMON>
<BOTANICAL>Trillium grandiflorum</BOTANICAL>
<ZONE>5</ZONE>
<LIGHT>Sun or Shade</LIGHT>
<PRICE>$3.90</PRICE>
<AVAILABILITY>042999</AVAI LABILITY>
</PLANT>
<PLANT>
<COMMON>Wake Robin</COMMON>
<BOTANICAL>Trillium grandiflorum</BOTANICAL>
<ZONE>5</ZONE>
<LIGHT>Sun or Shade</LIGHT>
<PRICE>$3.20</PRICE>
<AVAILABILITY>022199</AVAI LABILITY>
</PLANT>
<PLANT>
<COMMON>Violet, Dog-Tooth</COMMON>
<BOTANICAL>Erythronium americanum</BOTANICAL>
<ZONE>4</ZONE>
<LIGHT>Shade</LIGHT>
<PRICE>$9.04</PRICE>
<AVAILABILITY>020199</AVAI LABILITY>
</PLANT>
<PLANT>
<COMMON>Trout Lily</COMMON>
<BOTANICAL>Erythronium americanum</BOTANICAL>
<ZONE>4</ZONE>
<LIGHT>Shade</LIGHT>
<PRICE>$6.94</PRICE>
<AVAILABILITY>032499</AVAI LABILITY>
</PLANT>
<PLANT>
<COMMON>Adder's-Tongue</CO MMON>
<BOTANICAL>Erythronium americanum</BOTANICAL>
<ZONE>4</ZONE>
<LIGHT>Shade</LIGHT>
<PRICE>$9.58</PRICE>
<AVAILABILITY>041399</AVAI LABILITY>
</PLANT>
<PLANT>
<COMMON>Anemone</COMMON>
<BOTANICAL>Anemone blanda</BOTANICAL>
<ZONE>6</ZONE>
<LIGHT>Mostly Shady</LIGHT>
<PRICE>$8.86</PRICE>
<AVAILABILITY>122698</AVAI LABILITY>
</PLANT>
<PLANT>
<COMMON>Grecian Windflower</COMMON>
<BOTANICAL>Anemone blanda</BOTANICAL>
<ZONE>6</ZONE>
<LIGHT>Mostly Shady</LIGHT>
<PRICE>$9.16</PRICE>
<AVAILABILITY>071099</AVAI LABILITY>
</PLANT>
<PLANT>
<COMMON>Bee Balm</COMMON>
<BOTANICAL>Monarda didyma</BOTANICAL>
<ZONE>4</ZONE>
<LIGHT>Shade</LIGHT>
<PRICE>$4.59</PRICE>
<AVAILABILITY>050399</AVAI LABILITY>
</PLANT>
<PLANT>
<COMMON>Bergamot</COMMON>
<BOTANICAL>Monarda didyma</BOTANICAL>
<ZONE>4</ZONE>
<LIGHT>Shade</LIGHT>
<PRICE>$7.16</PRICE>
<AVAILABILITY>042799</AVAI LABILITY>
</PLANT>
<PLANT>
<COMMON>Black-Eyed Susan</COMMON>
<BOTANICAL>Rudbeckia hirta</BOTANICAL>
<ZONE>Annual</ZONE>
<LIGHT>Sunny</LIGHT>
<PRICE>$9.80</PRICE>
<AVAILABILITY>061899</AVAI LABILITY>
</PLANT>
<PLANT>
<COMMON>Buttercup</COMMON>
<BOTANICAL>Ranunculus</BOT ANICAL>
<ZONE>4</ZONE>
<LIGHT>Shade</LIGHT>
<PRICE>$2.57</PRICE>
<AVAILABILITY>061099</AVAI LABILITY>
</PLANT>
<PLANT>
<COMMON>Crowfoot</COMMON>
<BOTANICAL>Ranunculus</BOT ANICAL>
<ZONE>4</ZONE>
<LIGHT>Shade</LIGHT>
<PRICE>$9.34</PRICE>
<AVAILABILITY>040399</AVAI LABILITY>
</PLANT>
<PLANT>
<COMMON>Butterfly Weed</COMMON>
<BOTANICAL>Asclepias tuberosa</BOTANICAL>
<ZONE>Annual</ZONE>
<LIGHT>Sunny</LIGHT>
<PRICE>$2.78</PRICE>
<AVAILABILITY>063099</AVAI LABILITY>
</PLANT>
<PLANT>
<COMMON>Cinquefoil</COMMON >
<BOTANICAL>Potentilla</BOT ANICAL>
<ZONE>Annual</ZONE>
<LIGHT>Shade</LIGHT>
<PRICE>$7.06</PRICE>
<AVAILABILITY>052599</AVAI LABILITY>
</PLANT>
<PLANT>
<COMMON>Primrose</COMMON>
<BOTANICAL>Oenothera</BOTA NICAL>
<ZONE>3 - 5</ZONE>
<LIGHT>Sunny</LIGHT>
<PRICE>$6.56</PRICE>
<AVAILABILITY>013099</AVAI LABILITY>
</PLANT>
<PLANT>
<COMMON>Gentian</COMMON>
<BOTANICAL>Gentiana</BOTAN ICAL>
<ZONE>4</ZONE>
<LIGHT>Sun or Shade</LIGHT>
<PRICE>$7.81</PRICE>
<AVAILABILITY>051899</AVAI LABILITY>
</PLANT>
<PLANT>
<COMMON>Blue Gentian</COMMON>
<BOTANICAL>Gentiana</BOTAN ICAL>
<ZONE>4</ZONE>
<LIGHT>Sun or Shade</LIGHT>
<PRICE>$8.56</PRICE>
<AVAILABILITY>050299</AVAI LABILITY>
</PLANT>
<PLANT>
<COMMON>Jacob's Ladder</COMMON>
<BOTANICAL>Polemonium caeruleum</BOTANICAL>
<ZONE>Annual</ZONE>
<LIGHT>Shade</LIGHT>
<PRICE>$9.26</PRICE>
<AVAILABILITY>022199</AVAI LABILITY>
</PLANT>
<PLANT>
<COMMON>Greek Valerian</COMMON>
<BOTANICAL>Polemonium caeruleum</BOTANICAL>
<ZONE>Annual</ZONE>
<LIGHT>Shade</LIGHT>
<PRICE>$4.36</PRICE>
<AVAILABILITY>071499</AVAI LABILITY>
</PLANT>
<PLANT>
<COMMON>California Poppy</COMMON>
<BOTANICAL>Eschscholzia californica</BOTANICAL>
<ZONE>Annual</ZONE>
<LIGHT>Sun</LIGHT>
<PRICE>$7.89</PRICE>
<AVAILABILITY>032799</AVAI LABILITY>
</PLANT>
<PLANT>
<COMMON>Shooting Star</COMMON>
<BOTANICAL>Dodecatheon</BO TANICAL>
<ZONE>Annual</ZONE>
<LIGHT>Mostly Shady</LIGHT>
<PRICE>$8.60</PRICE>
<AVAILABILITY>051399</AVAI LABILITY>
</PLANT>
<PLANT>
<COMMON>Snakeroot</COMMON>
<BOTANICAL>Cimicifuga</BOT ANICAL>
<ZONE>Annual</ZONE>
<LIGHT>Shade</LIGHT>
<PRICE>$5.63</PRICE>
<AVAILABILITY>071199</AVAI LABILITY>
</PLANT>
<PLANT>
<COMMON>Cardinal Flower</COMMON>
<BOTANICAL>Lobelia cardinalis</BOTANICAL>
<ZONE>2</ZONE>
<LIGHT>Shade</LIGHT>
<PRICE>$3.02</PRICE>
<AVAILABILITY>022299</AVAI LABILITY>
</PLANT>
</CATALOG>
So for instance, just for practice sake I read and used the code from the url you left above. The code I used was:
<?php
$homepage = file_get_contents('http://www.w3schools.com/xml/plant_catalog.xml');
echo $homepage;
?>
and it brought back the XML response of:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Edited by XMLSpy -->
<CATALOG>
<PLANT>
<COMMON>Bloodroot</COMMON>
<BOTANICAL>Sanguinaria canadensis</BOTANICAL>
<ZONE>4</ZONE>
<LIGHT>Mostly Shady</LIGHT>
<PRICE>$2.44</PRICE>
<AVAILABILITY>031599</AVAI
</PLANT>
<PLANT>
<COMMON>Columbine</COMMON>
<BOTANICAL>Aquilegia canadensis</BOTANICAL>
<ZONE>3</ZONE>
<LIGHT>Mostly Shady</LIGHT>
<PRICE>$9.37</PRICE>
<AVAILABILITY>030699</AVAI
</PLANT>
<PLANT>
<COMMON>Marsh Marigold</COMMON>
<BOTANICAL>Caltha palustris</BOTANICAL>
<ZONE>4</ZONE>
<LIGHT>Mostly Sunny</LIGHT>
<PRICE>$6.81</PRICE>
<AVAILABILITY>051799</AVAI
</PLANT>
<PLANT>
<COMMON>Cowslip</COMMON>
<BOTANICAL>Caltha palustris</BOTANICAL>
<ZONE>4</ZONE>
<LIGHT>Mostly Shady</LIGHT>
<PRICE>$9.90</PRICE>
<AVAILABILITY>030699</AVAI
</PLANT>
<PLANT>
<COMMON>Dutchman's-Breeche
<BOTANICAL>Dicentra cucullaria</BOTANICAL>
<ZONE>3</ZONE>
<LIGHT>Mostly Shady</LIGHT>
<PRICE>$6.44</PRICE>
<AVAILABILITY>012099</AVAI
</PLANT>
<PLANT>
<COMMON>Ginger, Wild</COMMON>
<BOTANICAL>Asarum canadense</BOTANICAL>
<ZONE>3</ZONE>
<LIGHT>Mostly Shady</LIGHT>
<PRICE>$9.03</PRICE>
<AVAILABILITY>041899</AVAI
</PLANT>
<PLANT>
<COMMON>Hepatica</COMMON>
<BOTANICAL>Hepatica americana</BOTANICAL>
<ZONE>4</ZONE>
<LIGHT>Mostly Shady</LIGHT>
<PRICE>$4.45</PRICE>
<AVAILABILITY>012699</AVAI
</PLANT>
<PLANT>
<COMMON>Liverleaf</COMMON>
<BOTANICAL>Hepatica americana</BOTANICAL>
<ZONE>4</ZONE>
<LIGHT>Mostly Shady</LIGHT>
<PRICE>$3.99</PRICE>
<AVAILABILITY>010299</AVAI
</PLANT>
<PLANT>
<COMMON>Jack-In-The-Pulpit
<BOTANICAL>Arisaema triphyllum</BOTANICAL>
<ZONE>4</ZONE>
<LIGHT>Mostly Shady</LIGHT>
<PRICE>$3.23</PRICE>
<AVAILABILITY>020199</AVAI
</PLANT>
<PLANT>
<COMMON>Mayapple</COMMON>
<BOTANICAL>Podophyllum peltatum</BOTANICAL>
<ZONE>3</ZONE>
<LIGHT>Mostly Shady</LIGHT>
<PRICE>$2.98</PRICE>
<AVAILABILITY>060599</AVAI
</PLANT>
<PLANT>
<COMMON>Phlox, Woodland</COMMON>
<BOTANICAL>Phlox divaricata</BOTANICAL>
<ZONE>3</ZONE>
<LIGHT>Sun or Shade</LIGHT>
<PRICE>$2.80</PRICE>
<AVAILABILITY>012299</AVAI
</PLANT>
<PLANT>
<COMMON>Phlox, Blue</COMMON>
<BOTANICAL>Phlox divaricata</BOTANICAL>
<ZONE>3</ZONE>
<LIGHT>Sun or Shade</LIGHT>
<PRICE>$5.59</PRICE>
<AVAILABILITY>021699</AVAI
</PLANT>
<PLANT>
<COMMON>Spring-Beauty</COM
<BOTANICAL>Claytonia Virginica</BOTANICAL>
<ZONE>7</ZONE>
<LIGHT>Mostly Shady</LIGHT>
<PRICE>$6.59</PRICE>
<AVAILABILITY>020199</AVAI
</PLANT>
<PLANT>
<COMMON>Trillium</COMMON>
<BOTANICAL>Trillium grandiflorum</BOTANICAL>
<ZONE>5</ZONE>
<LIGHT>Sun or Shade</LIGHT>
<PRICE>$3.90</PRICE>
<AVAILABILITY>042999</AVAI
</PLANT>
<PLANT>
<COMMON>Wake Robin</COMMON>
<BOTANICAL>Trillium grandiflorum</BOTANICAL>
<ZONE>5</ZONE>
<LIGHT>Sun or Shade</LIGHT>
<PRICE>$3.20</PRICE>
<AVAILABILITY>022199</AVAI
</PLANT>
<PLANT>
<COMMON>Violet, Dog-Tooth</COMMON>
<BOTANICAL>Erythronium americanum</BOTANICAL>
<ZONE>4</ZONE>
<LIGHT>Shade</LIGHT>
<PRICE>$9.04</PRICE>
<AVAILABILITY>020199</AVAI
</PLANT>
<PLANT>
<COMMON>Trout Lily</COMMON>
<BOTANICAL>Erythronium americanum</BOTANICAL>
<ZONE>4</ZONE>
<LIGHT>Shade</LIGHT>
<PRICE>$6.94</PRICE>
<AVAILABILITY>032499</AVAI
</PLANT>
<PLANT>
<COMMON>Adder's-Tongue</CO
<BOTANICAL>Erythronium americanum</BOTANICAL>
<ZONE>4</ZONE>
<LIGHT>Shade</LIGHT>
<PRICE>$9.58</PRICE>
<AVAILABILITY>041399</AVAI
</PLANT>
<PLANT>
<COMMON>Anemone</COMMON>
<BOTANICAL>Anemone blanda</BOTANICAL>
<ZONE>6</ZONE>
<LIGHT>Mostly Shady</LIGHT>
<PRICE>$8.86</PRICE>
<AVAILABILITY>122698</AVAI
</PLANT>
<PLANT>
<COMMON>Grecian Windflower</COMMON>
<BOTANICAL>Anemone blanda</BOTANICAL>
<ZONE>6</ZONE>
<LIGHT>Mostly Shady</LIGHT>
<PRICE>$9.16</PRICE>
<AVAILABILITY>071099</AVAI
</PLANT>
<PLANT>
<COMMON>Bee Balm</COMMON>
<BOTANICAL>Monarda didyma</BOTANICAL>
<ZONE>4</ZONE>
<LIGHT>Shade</LIGHT>
<PRICE>$4.59</PRICE>
<AVAILABILITY>050399</AVAI
</PLANT>
<PLANT>
<COMMON>Bergamot</COMMON>
<BOTANICAL>Monarda didyma</BOTANICAL>
<ZONE>4</ZONE>
<LIGHT>Shade</LIGHT>
<PRICE>$7.16</PRICE>
<AVAILABILITY>042799</AVAI
</PLANT>
<PLANT>
<COMMON>Black-Eyed Susan</COMMON>
<BOTANICAL>Rudbeckia hirta</BOTANICAL>
<ZONE>Annual</ZONE>
<LIGHT>Sunny</LIGHT>
<PRICE>$9.80</PRICE>
<AVAILABILITY>061899</AVAI
</PLANT>
<PLANT>
<COMMON>Buttercup</COMMON>
<BOTANICAL>Ranunculus</BOT
<ZONE>4</ZONE>
<LIGHT>Shade</LIGHT>
<PRICE>$2.57</PRICE>
<AVAILABILITY>061099</AVAI
</PLANT>
<PLANT>
<COMMON>Crowfoot</COMMON>
<BOTANICAL>Ranunculus</BOT
<ZONE>4</ZONE>
<LIGHT>Shade</LIGHT>
<PRICE>$9.34</PRICE>
<AVAILABILITY>040399</AVAI
</PLANT>
<PLANT>
<COMMON>Butterfly Weed</COMMON>
<BOTANICAL>Asclepias tuberosa</BOTANICAL>
<ZONE>Annual</ZONE>
<LIGHT>Sunny</LIGHT>
<PRICE>$2.78</PRICE>
<AVAILABILITY>063099</AVAI
</PLANT>
<PLANT>
<COMMON>Cinquefoil</COMMON
<BOTANICAL>Potentilla</BOT
<ZONE>Annual</ZONE>
<LIGHT>Shade</LIGHT>
<PRICE>$7.06</PRICE>
<AVAILABILITY>052599</AVAI
</PLANT>
<PLANT>
<COMMON>Primrose</COMMON>
<BOTANICAL>Oenothera</BOTA
<ZONE>3 - 5</ZONE>
<LIGHT>Sunny</LIGHT>
<PRICE>$6.56</PRICE>
<AVAILABILITY>013099</AVAI
</PLANT>
<PLANT>
<COMMON>Gentian</COMMON>
<BOTANICAL>Gentiana</BOTAN
<ZONE>4</ZONE>
<LIGHT>Sun or Shade</LIGHT>
<PRICE>$7.81</PRICE>
<AVAILABILITY>051899</AVAI
</PLANT>
<PLANT>
<COMMON>Blue Gentian</COMMON>
<BOTANICAL>Gentiana</BOTAN
<ZONE>4</ZONE>
<LIGHT>Sun or Shade</LIGHT>
<PRICE>$8.56</PRICE>
<AVAILABILITY>050299</AVAI
</PLANT>
<PLANT>
<COMMON>Jacob's Ladder</COMMON>
<BOTANICAL>Polemonium caeruleum</BOTANICAL>
<ZONE>Annual</ZONE>
<LIGHT>Shade</LIGHT>
<PRICE>$9.26</PRICE>
<AVAILABILITY>022199</AVAI
</PLANT>
<PLANT>
<COMMON>Greek Valerian</COMMON>
<BOTANICAL>Polemonium caeruleum</BOTANICAL>
<ZONE>Annual</ZONE>
<LIGHT>Shade</LIGHT>
<PRICE>$4.36</PRICE>
<AVAILABILITY>071499</AVAI
</PLANT>
<PLANT>
<COMMON>California Poppy</COMMON>
<BOTANICAL>Eschscholzia californica</BOTANICAL>
<ZONE>Annual</ZONE>
<LIGHT>Sun</LIGHT>
<PRICE>$7.89</PRICE>
<AVAILABILITY>032799</AVAI
</PLANT>
<PLANT>
<COMMON>Shooting Star</COMMON>
<BOTANICAL>Dodecatheon</BO
<ZONE>Annual</ZONE>
<LIGHT>Mostly Shady</LIGHT>
<PRICE>$8.60</PRICE>
<AVAILABILITY>051399</AVAI
</PLANT>
<PLANT>
<COMMON>Snakeroot</COMMON>
<BOTANICAL>Cimicifuga</BOT
<ZONE>Annual</ZONE>
<LIGHT>Shade</LIGHT>
<PRICE>$5.63</PRICE>
<AVAILABILITY>071199</AVAI
</PLANT>
<PLANT>
<COMMON>Cardinal Flower</COMMON>
<BOTANICAL>Lobelia cardinalis</BOTANICAL>
<ZONE>2</ZONE>
<LIGHT>Shade</LIGHT>
<PRICE>$3.02</PRICE>
<AVAILABILITY>022299</AVAI
</PLANT>
</CATALOG>
Once you've loaded in your XML string, you'd create a new simpleXMLElement and then you access the data from that. Using your XML as an example, something like this:
//load the XML file as a string
$xml = file_get_contents('data.xml');
//create a new SimpleXMLElement from the string
$plants = new SimpleXMLElement($xml);
//Loop through the XML
foreach ($plants as $plant):
//examine each PLANT
var_dump($plant);
//get some specific nodes
echo $plant->COMMON;
echo $plant->BOTANICAL;
endforeach;
From this you can see that the XML is converted into an object that contains an array named "PLANT" with 36 elements. Each element of the PLANT array is itself a PHP object (of parallel construction) giving details about the particular plant.
<?php // RAY_temp_tarrigo.php
error_reporting(E_ALL);
echo '<pre>';
// SEE http://www.experts-exchange.com/Software/Server_Software/Web_Servers/Q_28352829.html
// LOCATION OF THE TEST DATA
$url = 'http://www.w3schools.com/xml/plant_catalog.xml';
// READ THE TEST DATA AND MAKE AN OBJECT
$xml = file_get_contents($url);
$obj = SimpleXML_Load_String($xml);
// SHOW WHAT WE GOT
var_dump($obj);
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
This last comment from Ray really helped a lot. After I tweaked it a bit I could see how I could bring all the results back from the XML list. I assume that PHP_EOL; takes it to the of the records. Thus why I got one result back. I was able to modify it now so it would bring back all the results. I can also see how I can pick the nodes I need. Very helpful. I thank you so much for the help.
Not sure how the accepted answer is different to the one I provided earlier, but hey-ho!
PHP_EOL is an end of line character (for adding new lines after a string)
PHP_EOL is an end of line character (for adding new lines after a string)
ASKER
Well, I will explain the reasoning behind why I did what I did. When I used your example in some testing I got back a lot of information not just the actual value of a particular node. I just wanted basically the value like "flower" or Patunia or something like that. The other example I got that info back after doing some tweaking. I wanted to give credit to you, but a moderator told me that I needed to be specific when choosing a solution since it really needs to be the actual solution. I might have been too literal in the way I interpreted what they told me, but that was why I did what I did. If I could give credit to you, I gladly would. I learned something from you definitely.
The reason you got everything back is because of the var_dump() function - it was put in so you could see exactly what you had access to in the loop. Ray's code also had the var_dump() but it was commented out.
For future reference, you can accept more than one solution as the answer - in fact you're encouraged to do this when several experts help you to get answers - whichever moderator told you to accept one answer is simply wrong!
Pleased you got it working though ;)
For future reference, you can accept more than one solution as the answer - in fact you're encouraged to do this when several experts help you to get answers - whichever moderator told you to accept one answer is simply wrong!
Pleased you got it working though ;)
Thanks for the points and thanks for using EE.
To clarify, PHP_EOL is a predefined and context-aware constant for the end-of-line character. Different OS environments choose different end-of-line characters with \n, \r, \r\n, etc. PHP_EOL sorts this out for you and makes the code more portable across different systems.
Best regards, ~Ray
To clarify, PHP_EOL is a predefined and context-aware constant for the end-of-line character. Different OS environments choose different end-of-line characters with \n, \r, \r\n, etc. PHP_EOL sorts this out for you and makes the code more portable across different systems.
Best regards, ~Ray
ASKER
I actually tried to adapt what I learned from your posts and it seems to not be working right now. It is a new XML query. If I just put the url in the browser it does bring back data. However, trying to access it the way you did i get nothing back in the web page. I modified my code in the foreach as follows:
The end result when I just put the url in the browser to test the XML format looks like the following in the attachment. Sorry had to blur out some stuff since it contains logon info.
Untitled-1.jpg
foreach ($obj->Inventory as $thing)
{
echo $thing->Quantity . ' is the total ' . $thing->CountryName . '<br />';
}
The end result when I just put the url in the browser to test the XML format looks like the following in the attachment. Sorry had to blur out some stuff since it contains logon info.
Untitled-1.jpg
The data you posted originally is nothing like the jpg you've just shown us. That doesn't even look like XML so I'm not surprised that you can't get it to work.
What was the point of posting the original data is it doesn't represent what you're actually working with?
If you want us to help you, you need to post your working data set.
What was the point of posting the original data is it doesn't represent what you're actually working with?
If you want us to help you, you need to post your working data set.
ASKER
I did not have access to the account yet. The data I was pulling I have to pay for. I thought I could use another source of data to learn the concepts and then apply to what I would have to pay for. I decided to pay for the service when I though I would be able to traverse the data.
OK.
Like I said though, if you need help, you'll have to post your data. The JPG doesn't look like XML but I could be wrong - post it up and I'll have a look.
Like I said though, if you need help, you'll have to post your data. The JPG doesn't look like XML but I could be wrong - post it up and I'll have a look.
Ah - just realised you've accepted the answer to this qustion, so just post another question with your real data attached.
ASKER
I actually thought that this question was no longer available earlier today as subject matter that was considered still unsolved, so I posted the question with the image file as a new question. Ray actually just replied to it. Sorry for the mess, but I did not see a way to reopen this original question.