Search Results

Search found 137 results on 6 pages for 'simplexml'.

Page 1/6 | 1 2 3 4 5 6  | Next Page >

  • SimpleXml class not found

    - by Danten
    After initiating a new SimpleXml object: $xml = new SimpleXML($xmlStr); PHP errors out: Fatal error: Class 'SimpleXML' not found PHP info reads: Simplexml support enabled Revision $Revision: 1.151.2.22.2.35.2.32 $ Schema support enabled What could possibly be going wrong?

    Read the article

  • PHP DOM vs SimpleXML for Atom GData feed parsing

    - by Geoff Adams
    I'm building a library to access the Google Analytics Data Export API. All the data the library accesses is in Atom format and utilises numerous different namespaces throughout. My experiments with the API have used SimpleXML for parsing so far, especially as all I have been doing is accessing the data held within the feed. Now I'm coming to write a library I am wondering whether forging ahead with SimpleXML will be adequate or whether the enhanced functionality of the DOM module in PHP would be of benefit in the future. I haven't written much code for this part of the library yet so the choice is still open. I have read that the PHP DOM module can be a better choice if you need to build an XML DOM on the fly or modify an existing one, but I'm not entirely sure I would need that functionality anyway due to the nature of the API (no pushing data to the server, for instance). SimpleXML is certainly easier to use and I have seen people saying that for read-only situations it is all you need. Essentially the question is, what would you use? Compatibility will not be an issue as the server configuration will match the application's requirements. Is it worth building the library with PHP DOM in mind or should I stick with SimpleXML for now? Update: Here are two examples of the kind of feeds I will be dealing with: Account feed Data feed

    Read the article

  • PHP's SimpleXML not handling &#8217 ; properly

    - by Matty
    I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this into a ’. What can I do to stop this? Just to answer some of the questions that have come up - I'm pulling an RSS feed using CURL. If I output this directly to the browser, the ’ displays as ’ which is what's expected. When I create a new SimpleXMLElement using this, (e.g. $xml = new SimpleXmlElement($raw_feed); and dump the $xml variable, every instance of ’ is replaced with ’. It appears that SimpleXML is having trouble with UTF-8 ampersand encoded characters. (The XML declaration specifies UTF-8.) I do have control over the feed after CURL has retrieved the feed before it's used to construct a SimpleXML element.

    Read the article

  • PHP / SimpleXML - Why does Simplexml_load_string() fail to parse Google Weather API xml in Chinese (

    - by John Himmelman
    I'm trying to load parse a Google Weather API response (chinese response). Here is the API call.. http://www.google.com/ig/api?weather=11791&hl=zh-CN // This code fails with the following error $xml = simplexml_load_file('http://www.google.com/ig/api?weather=11791&hl=zh-CN'); ( ! ) Warning: simplexml_load_string() [function.simplexml-load-string]: Entity: line 1: parser error : Input is not proper UTF-8, indicate encoding ! Bytes: 0xB6 0xE0 0xD4 0xC6 in C:\htdocs\weather.php on line 11 Why does loading this response fail? How do I encode/decode the response so that simplexml loads it properly?

    Read the article

  • SimpleXML SOAP response Namespace issues

    - by Stu
    Hi. After spending SEVERAL frustrated hours on this I am asking for your help. I am trying to get the content of particular nodes from a SOAP response. The response is $XmlStr = <?xml version="1.0" encoding="UTF-8"?><env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope"<xmlns:ns1="http://soap.xxxxxx.co.uk/"><env:Body><ns1:PlaceOrderResponse><xxxxxOrderNumber></xxxxxOrderNumber><ErrorArray><Error><ErrorCode>24</ErrorCode><ErrorText>The+client+order+number+3002254+is+already+in+use</ErrorText></Error><Error><ErrorCode>1</ErrorCode><ErrorText>Aborting</ErrorText></Error></ErrorArray></ns1:PlaceOrderResponse></env:Body></env:Envelope> I am trying to get at the nodes and children of <ErrorArray. Because of the XML containing namespaces $XmlArray = new SimpleXMLElement($XmlStr); foreach ($XmlArray->env:Envelope->env:Body->ns1:PlaceOrderResponse->ErrorArray->Error as $Error) { echo $Error->ErrorCode."<br />";<br /> } doesn't work. I have read a number of articles such as http://www.sitepoint.com/blogs/2005/10/20/simplexml-and-namespaces/ htp://blog.stuartherbert.com/php/2007/01/07/using-simplexml-to-parse-rss-feeds/ and about 20 questions on this site which unfortunately are not helping. (the second link has htp:// as a newbie here I cannot post more than one link) Even writing, $XmlArray = new SimpleXMLElement($XmlStr); echo "<br /><br /><pre>\n"; print_r($XmlArray); echo "<pre><br /><br />\n"; gives SimpleXMLElement Object ( ) which makes me wonder if the soap response ($XmlStr) is actually a valid input for SimpleXMLElement. It seems that the line $XmlArray = new SimpleXMLElement($XmlStr); is not doing what I expect it to. Any help on how to get the nodes from the XML above would be very welcome. Obviously getting it to work (having a working example) is what I need in the short term, but if someone could help me understand what I am doing wrong would be better in the long term. Cheers. Stu

    Read the article

  • Extracting Certain XML Elements with PHP SimpleXML

    - by Peter
    I am having some problems parsing this piece of XML using SimpleXML. There is always only one Series element, and a variable number of Episode elements beneath. I want to parse XML so I can store the Series data in one table, and all the Episode data in another table. XML: <Data> <Series> <id>80348</id> <Genre>|Action and Adventure|Comedy|Drama|</Genre> <IMDB_ID>tt0934814</IMDB_ID> <SeriesID>68724</SeriesID> <SeriesName>Chuck</SeriesName> <banner>graphical/80348-g.jpg</banner> </Series> <Episode> <id>935481</id> <Director>Robert Duncan McNeill</Director> <EpisodeName>Chuck Versus the Third Dimension 2D</EpisodeName> <EpisodeNumber>1</EpisodeNumber> <seasonid>27984</seasonid> <seriesid>80348</seriesid> </Episode> <Episode> <id>935483</id> <Director>Robert Duncan McNeill</Director> <EpisodeName>Buy More #15: Employee Health</EpisodeName> <EpisodeNumber>2</EpisodeNumber> <seasonid>27984</seasonid> <seriesid>80348</seriesid> </Episode> </Data> When I attempt to access just the first Series element and child nodes, or iterate through the Episode elements only it does not work. I have also tried to use DOMDocument with SimpleXML, but could not get that to work at all. PHP Code: <?php if(file_exists('en.xml')) { $data = simplexml_load_file('en.xml'); foreach($data as $series) { echo 'id: <br />' . $series->id; echo 'imdb: <br />' . $series->IMDB_ID; } } ?> Output: id:80348 imdb:tt0934814 id:935481 imdb: id:1534641 imdb: Any help would be greatly appreciated.

    Read the article

  • Remove a child with a specific attribute, in SimpleXML for PHP

    - by TimTowdi
    I have several identical elements with different attributes that I'm accessing with SimpleXML: <data> <seg id="A1"/> <seg id="A5"/> <seg id="A12"/> <seg id="A29"/> <seg id="A30"/> </data> I need to remove a specific seg element, with an id of "A12", how can I do this? I've tried looping through the seg elements and unsetting the specific one, but this doesn't work, the elements remain. foreach($doc->seg as $seg) { if($seg['id'] == 'A12') { unset($seg); } }

    Read the article

  • php: simplexml exception retry

    - by exceptionhandlingnoob
    I am querying an API using SimpleXML which will occasionally fail for reasons unknown. I would like to have the script retry up to 5 times. How can I do this? I assume it has something to do with wrapping the object in a try/catch, but I'm not very experienced with this -- have tried to read the manual on exception handling but am still at a loss. Thanks for any help :) // set up xml handler $xmlstr = file_get_contents($request); $xml = new SimpleXMLElement($xmlstr); Here is the error message I am receiving: [function.file-get-contents]: failed to open stream: HTTP request failed!

    Read the article

  • PHP simplexml Entities

    - by FFish
    What's going one here? $string = <<<XML <?xml version="1.0" encoding="UTF-8"?> <album> <img src="002.jpg" caption="w&aacute;ssup?" /> </album> XML; $xml = simplexml_load_string($string); // $xmlobj = simplexml_load_file("xml.xml"); // same thing echo "<pre>"; var_dump($xml); echo "</pre>"; Error: Warning: simplexml_load_string() [function.simplexml-load-string]: Entity: line 5: parser error : Entity 'aacute' not defined

    Read the article

  • Looping through a SimpleXML object

    - by Aditya
    I have a simpleXml object and want to read the data from the object , I am new to PHP and dont quite know how to do this. The object details are as follows. I need to read [description] and [hours]. Thankyou. SimpleXMLElement Object ( [@attributes] = Array ( [type] = array ) [time-entry] = Array ( [0] = SimpleXMLElement Object ( [date] = 2010-01-26 [description] = TCDM1 data management: sort & upload NFP SubProducers list [hours] = 1.0 [id] = 21753865 [person-id] = 350501 [project-id] = 4287373 [todo-item-id] = SimpleXMLElement Object ( [@attributes] = Array ( [type] = integer [nil] = true ) ) ) [1] = SimpleXMLElement Object ( [date] = 2010-01-27 [description] = PDCH1: HTML [hours] = 0.25 [id] = 21782012 [person-id] = 1828493 [project-id] = 4249185 [todo-item-id] = SimpleXMLElement Object ( [@attributes] = Array ( [type] = integer [nil] = true ) ) ). Please help me. I tries a lot of stuff , but not getting the syntax right.

    Read the article

  • How do I loop through a SimpleXML object in PHP

    - by Aditya
    I have a simpleXml object and want to read the data from the object , I am new to PHP and dont quite know how to do this. The object details are as follows. I need to read [description] and [hours]. Thankyou. SimpleXMLElement Object ( [@attributes] = Array ( [type] = array ) [time-entry] = Array ( [0] = SimpleXMLElement Object ( [date] = 2010-01-26 [description] = TCDM1 data management: sort & upload NFP SubProducers list [hours] = 1.0 [id] = 21753865 [person-id] = 350501 [project-id] = 4287373 [todo-item-id] = SimpleXMLElement Object ( [@attributes] = Array ( [type] = integer [nil] = true ) ) ) [1] = SimpleXMLElement Object ( [date] = 2010-01-27 [description] = PDCH1: HTML [hours] = 0.25 [id] = 21782012 [person-id] = 1828493 [project-id] = 4249185 [todo-item-id] = SimpleXMLElement Object ( [@attributes] = Array ( [type] = integer [nil] = true ) ) ). Please help me. I tries a lot of stuff , but not getting the syntax right.

    Read the article

  • "Trying to get property of non-object" error with SimpleXML and PHP

    - by SooDesuNe
    I'm using a PHP script with SimpleXML to parse an XML feed. I have no control over the content of the XML. try { $xml = @new SimpleXMLElement($fetchResult); } catch (Exception $e) { errorHandle($e->getMessage());} $userNick = $xml->View->ScrollView->VBoxView->View->MatrixView->VBoxView[0]->HBoxView->TextView->SetFontStyle->b; foreach ($xml->View->ScrollView->VBoxView->View->MatrixView->VBoxView[0]->VBoxView as $pathToSubTree){ foreach ($pathToSubTree->MatrixView->View->VBoxView->VBoxView->HBoxView[0]->VBoxView->MatrixView->VBoxView as $canopy){ //Do some stuff now that we've found the canopy of the tree } $canopy = $pathToSubTree->MatrixView->View->VBoxView->VBoxView->HBoxView[0]->VBoxView->MatrixView->VBoxView; if(is_null($canopy)){ //Do some stuff stuff is the canopy was not traceable } } $pathToSubTree = $xml->View->ScrollView->VBoxView->View->MatrixView->VBoxView[0]->VBoxView; if(is_null($pathToSubTree)){ //Do some stuff stuff is the subTree path was not traceable } unset($xml); I'm getting lots of two errors, which I'm sure are related to the same cause: PHP Notice: Trying to get property of non-object in myScript.php on line 45 PHP Warning: Invalid argument supplied for foreach() in myScript.php on line 45 PHP Notice: Trying to get property of non-object in myScript.php on line 76 Line 45 is (from above): foreach ($pathToSubTree->MatrixView->View->VBoxView->VBoxView->HBoxView[0]->VBoxView->MatrixView->VBoxView as $canopy){ Line 76 is (from above): $canopy = $pathToSubTree->MatrixView->View->VBoxView->VBoxView->HBoxView[0]->VBoxView->MatrixView->VBoxView; I'm pretty sure this error is caused by one of the arrays in my path not being an array for the particular XML, but some times it CAN be an array. What's the correct way to deal with these?

    Read the article

  • PHP's SimpleXML: How to use colons in names

    - by nute
    I am trying to generate an RSS Google Merchant, using SimpleXML. The sample given by Google is: <?xml version="1.0"?> <rss version="2.0" xmlns:g="http://base.google.com/ns/1.0"> <channel> <title>The name of your data feed</title> <link>http://www.example.com</link> <description>A description of your content</description> <item> <title>Red wool sweater</title> <link> http://www.example.com/item1-info-page.html</link> <description>Comfortable and soft, this sweater will keep you warm on those cold winter nights.</description> <g:image_link>http://www.example.com/image1.jpg</g:image_link> <g:price>25</g:price> <g:condition>new</g:condition> <g:id>1a</g:id> </item> </channel> </rss> My code has things like: $product->addChild("g:condition", 'new'); Which generates: <condition>new</condition> I read online that I should instead use: $product->addChild("g:condition", 'new', 'http://base.google.com/ns/1.0'); Which now generates: <g:condition xmlns:g="http://base.google.com/ns/1.0">new</g:condition> This seems very counter-intuitive to me, as now the "xmlns" declaration is on almost EVERY line of my RSS feed intead of just once in the root element. Am I missing something?

    Read the article

  • PHP: SimpleXML and Arrays

    - by acemasta
    When I run this code: foreach($xml->movie as $movie) { if(isset($movie->photos)) { foreach ($movie->photos as $photo) { echo $photo."&nbsp;"; } echo "<hr/>"; } } I get nice output of the actual data, e.g. a row looks like 06397001.jpg 06397002.jpg 06397003.jpg 06397004.jpg 06397005.jpg But when I throw it in an array, it includes all the SimpleXML wrapper tags and the jpgs are not at the root of the array. code: foreach($xml->movie as $movie) { if(isset($movie->photos)) { $photos = array(); foreach ($movie->photos as $photo) { $photos[] = $photo; } } else $photos = ""; var_dump($photos); echo "<hr />"; } e.g. same row looks like array(5) { [0]= object(SimpleXMLElement)#11 (1) { [0]= string(12) "06397001.jpg" } [1]= object(SimpleXMLElement)#12 (1) { [0]= string(12) "06397002.jpg" } [2]= object(SimpleXMLElement)#13 (1) { [0]= string(12) "06397003.jpg" } [3]= object(SimpleXMLElement)#14 (1) { [0]= string(12) "06397004.jpg" } [4]= object(SimpleXMLElement)#15 (1) { [0]= string(12) "06397005.jpg" } } Why is this happening/how can I remove this so I just get an array of the photos at root level like when I echo it? Thanks, sorry for the single line code formatting; was messing up when I tried to paste directly with line breaks.

    Read the article

  • PHP SimpleXML recursive function to list children and attibutes

    - by Phill Pafford
    I need some help on the SimpleXML calls for a recursive function that lists the elements name and attributes. Making a XML config file system but each script will have it's own config file as well as a new naming convention. So what I need is an easy way to map out all the elements that have attributes, so like in example 1 I need a simple way to call all the processes but I don't know how to do this without hard coding the elements name is the function call. Is there a way to recursively call a function to match a child element name? I did see the xpath functionality but I don't see how to use this for attributes. Any ideas? Also does the XML in the examples look correct? can I structure my XML like this? Example 1: <application> <processes> <process id="123" name="run batch A" /> <process id="122" name="run batch B" /> <process id="129" name="run batch C" /> </processes> <connections> <databases> <database usr="test" pss="test" hst="test" dbn="test" /> </databases> <shells> <ssh usr="test" pss="test" hst="test-2" /> <ssh usr="test" pss="test" hst="test-1" /> </shells> </connections> </application> Example 2: <config> <queues> <queue id="1" name="test" /> <queue id="2" name="production" /> <queue id="3" name="error" /> </queues> </config> Pseudo code: // Would return matching process id getProcess($process_id) { return the process attributes as array that are in the XML } // Would return matching DBN (database name) getDatabase($database_name) { return the database attributes as array that are in the XML } // Would return matching SSH Host getSSHHost($ssh_host) { return the ssh attributes as array that are in the XML } // Would return matching SSH User getSSHUser($ssh_user) { return the ssh attributes as array that are in the XML } // Would return matching Queue getQueue($queue_id) { return the queue attributes as array that are in the XML } EDIT: Can I pass two parms? on the first method you have suggested @Gordon public function findProcessById($id, $name) { $attr = false; $el = $this->xml->xpath("//process[@id='$id']"); // How do I also filter by the name? if($el && count($el) === 1) { $attr = (array) $el[0]->attributes(); $attr = $attr['@attributes']; } return $attr; }

    Read the article

  • SimpleXML not pulling correct link

    - by kylex
    My code does not pull the proper link for the item. Instead it's getting the previous item's link. Any suggestions? Thanks! <?php // Load the XML data from the specified file name. // The second argument (NULL) allows us to specify additional libxml parameters, // we don't need this so we'll leave it as NULL. The third argument however is // important as it informs simplexml to handle the first parameter as a file name // rather than a XML formatted string. $pFile = new SimpleXMLElement("http://example.blogspot.com/feeds/posts/default?alt=rss", null, true); // Now that we've loaded our XML file we can begin to parse it. // We know that a channel element should be available within the, // document so we begin by looping through each channel foreach ($pFile->channel as $pChild) { // Now we want to loop through the items inside this channel { foreach ($pFile->channel->item as $pItem) { // If this item has child nodes as it should, // loop through them and print out the data foreach ($pItem->children() as $pChild) { // We can check the name of this node using the getName() method. // We can then use this information, to, for example, embolden // the title or format a link switch ($pChild->getName()) { case 'pubDate': $date = date('l, F d, Y', strtotime($pChild)); echo "<p class=\"blog_time\">$date</p>"; break; case 'link': $link = $pChild; break; case 'title': echo "<p class=\"blog_title\"><a href=\"$link\">$pChild</a></p>"; break; case 'description': // echo substr(strip_tags($pChild), 0 , 270) . "..."; break; case 'author': echo ""; break; case 'category': echo ""; break; case 'guid': echo ""; break; default: // echo strip_tags($pChild) . "<br />\n"; break; } } } } } ?>

    Read the article

  • Looping through a SimpleXML object, or turning the whole thing into an array.

    - by Coffee Cup
    I'm trying to work out how to iterate though a returned SimpleXML object. I'm using a toolkit called Tarzan AWS, which connects to Amazon Web Services (SimpleDB, S3, EC2, etc). I'm specifically using SimpleDB. I can put data into the Amazon SimpleDB service, and I can get it back. I just don't know how to handle the SimpleXML object that is returned. The Tarzan AWS documentation says this: Look at the response to navigate through the headers and body of the response. Note that this is an object, not an array, and that the body is a SimpleXML object. Here's a sample of the returned SimpleXML object: [body] = SimpleXMLElement Object ( [QueryWithAttributesResult] = SimpleXMLElement Object ( [Item] = Array ( [0] = SimpleXMLElement Object ( [Name] = message12413344443260 [Attribute] = Array ( [0] = SimpleXMLElement Object ( [Name] = active [Value] = 1 ) [1] = SimpleXMLElement Object ( [Name] = user [Value] = john ) [2] = SimpleXMLElement Object ( [Name] = message [Value] = This is a message. ) [3] = SimpleXMLElement Object ( [Name] = time [Value] = 1241334444 ) [4] = SimpleXMLElement Object ( [Name] = id [Value] = 12413344443260 ) [5] = SimpleXMLElement Object ( [Name] = ip [Value] = 10.10.10.1 ) ) ) [1] = SimpleXMLElement Object ( [Name] = message12413346907303 [Attribute] = Array ( [0] = SimpleXMLElement Object ( [Name] = active [Value] = 1 ) [1] = SimpleXMLElement Object ( [Name] = user [Value] = fred ) [2] = SimpleXMLElement Object ( [Name] = message [Value] = This is another message ) [3] = SimpleXMLElement Object ( [Name] = time [Value] = 1241334690 ) [4] = SimpleXMLElement Object ( [Name] = id [Value] = 12413346907303 ) [5] = SimpleXMLElement Object ( [Name] = ip [Value] = 10.10.10.2 ) ) ) ) So what code do I need to get through each of the object items? I'd like to loop through each of them and handle it like a returned mySQL query. For example, I can query SimpleDB and then loop though the SimpleXML so I can display the results on the page. Alternatively, how do you turn the whole shebang into an array? I'm new to SimpleXML, so I apologise if my questions aren't specific enough.

    Read the article

  • PHP simpleXML parsing

    - by FFish
    I need currency conversion, euro to dollar. The European Central bank provides the rates here: http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml I can get the USD rate by using the first node, but what if they change the order? Do I need something more reliable? I have no idea how.. $xml = @simplexml_load_file('http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml'); echo "dollar: " . $xml->Cube->Cube->Cube[0]->attributes()->rate;

    Read the article

  • SimpleXML - "Node no longer exists"

    - by SubZane
    Hi I'm trying to get the video data from this youtube playlist feed and add the interesting data to an array and use that later, but as you can see from the feed some videolinks are "dead" and that results in problems for my code. The error I get is "Node no longer exists" when I try to access $attrs['url']. I've tried for hours to find a way to check if the node exists before I access it but I have no luck. If anyone could help me to either parse the feed some other way with the same result or create a if-node-exists check that works I would be most happy. Thank you in advance $url = 'http://gdata.youtube.com/feeds/api/playlists/18A7E36C33EF4B5D?v=2'; $sxml = simplexml_load_file($url); $i = 0; $videoobj; foreach ($sxml->entry as $entry) { // get nodes in media: namespace for media information $media = $entry->children('http://search.yahoo.com/mrss/'); // get video player URL $attrs = $media->group->player->attributes(); $videoobj[$i]['url'] = $attrs['url']; // get video thumbnail $attrs = $media->group->thumbnail[0]->attributes(); $videoobj[$i]['thumb'] = $attrs['url']; $videoobj[$i]['title'] = $media->group->title; $i++; }

    Read the article

  • PHP SimpleXML - Remove xpath node

    - by Peter John
    Hi, I'm a little confused as to how i can delete a parent node of something which i can find via an xpath search: $xml = simplexml_load_file($filename); $data = $xml->xpath('//items/info[item_id="' . $item_id . '"]'); $parent = $data[0]->xpath("parent::*"); unset($parent); So, it finds the item id, no problems there - but the unset isnt getting rid of this <items> node. All i want to do is remove the <items>...</items> for this product. Obviously, there are loads of <items> nodes in the xml file so it cant do unset($xml->data->items) as that would delete everything. Any ideas much appreciated :-)

    Read the article

  • php , SimpleXML, while loop

    - by Michael
    I'm trying to get some information from ebay api and store it in database . I used simple xml to extract the information but I have a small issue as the information is not displayed for some items . if I make a print to the simple_xml I can see very well that the information is provided by ebay api . I have $items = "220617293997,250645537939,230485306218,110537213815,180519294810"; $number_of_items = count(explode(",", $items)); $xml = $baseClass->getContent("http://open.api.ebay.com/shopping?callname=GetMultipleItems&responseencoding=XML&appid=Morcovar-c74b-47c0-954f-463afb69a4b3&siteid=0&version=525&IncludeSelector=ItemSpecifics&ItemID=$items"); writeDoc($xml, "api.xml"); //echo $xml; $getvalues = simplexml_load_file('api.xml'); // print_r($getvalue); $number = "0"; while($number < 6) { $item_number = $getvalues->Item[$number]->ItemID; $location = $getvalues->Item[$number]->Location; $title = $getvalues->Item[$number]->Title; $price = $getvalues->Item[$number]->ConvertedCurrentPrice; $manufacturer = $getvalues->Item[$number]->ItemSpecifics->NameValueList[3]->Value; $model = $getvalues->Item[$number]->ItemSpecifics->NameValueList[4]->Value; $mileage = $getvalues->Item[$number]->ItemSpecifics->NameValueList[5]->Value; echo "item number = $item_number <br>localtion = $location<br>". "title = $title<br>price = $price<br>manufacturer = $manufacturer". "<br>model = $model<br>mileage = $mileage<br>"; $number++; } the above code returns item number = localtion = title = price = manufacturer = model = mileage = item number = 230485306218 localtion = Coventry, Warwickshire title = 2001 LAND ROVER RANGE ROVER VOGUE AUTO GREEN price = 3635.07 manufacturer = Land Rover model = Range Rover mileage = 76000 item number = 220617293997 localtion = Crawley, West Sussex title = 2004 CITROEN C5 HDI LX RED price = 3115.77 manufacturer = Citroen model = C5 mileage = 76000 item number = 180519294810 localtion = London, London title = 2000 VOLKSWAGEN POLO 1.4 SILVER 16V NEED GEAR BOX price = 905.06 manufacturer = Right-hand drive model = mileage = Standard Car item number = localtion = title = price = manufacturer = model = mileage = As you can see the information is not retrieved for a few items ... If I replace the $number manually like " $item_number = $getvalues-Item[4]-ItemID;" works well for any number .

    Read the article

  • PHP sorting issue with simpleXML

    - by tugbucket
    test.xml: <?xml version="1.0"?> <props> <prop> <state statename="Mississippi"> <info> <code>a1</code> <location>Jackson</location> </info> <info> <code>d2</code> <location>Gulfport</location> </info> <info> <code>g6</code> <location>Hattiesburg</location> </info> </state> <state statename="Texas"> <info> <code>i9</code> <location>Dallas</location> </info> <info> <code>a7</code> <location>Austin</location> </info> </state> <state statename="Maryland"> <info> <code>s5</code> <location>Mount Laurel</location> </info> <info> <code>f0</code> <location>Baltimore</location> </info> <info> <code>h4</code> <location>Annapolis</location> </info> </state> </prop> </props> test.php // start the sortCities function sortCities($a, $b){ return strcmp($a->location, $b->location); } // start the sortStates function sortStates($t1, $t2) { return strcmp($t1['statename'], $t2['statename']); } $props = simplexml_load_file('test.xml'); foreach ($props->prop as $prop) { $sortedStates = array(); foreach($prop->state as $states) { $sortedStates[] = $states; } usort($sortedStates, "sortStates"); // finish the sortStates /* --- */ echo '<pre>'."\n"; print_r($sortedStates); echo '</pre>'."\n"; /* --- */ foreach ($prop->children() as $stateattr) { // this doesn't do it //foreach($sortedStates as $hotel => @attributes){ // blargh! if(isset($stateattr->info)) { $statearr = $stateattr->attributes(); echo '<optgroup label="'.$statearr['statename'].'">'."\n"; $options = array(); foreach($stateattr->info as $info) { $options[] = $info; } usort($options, "sortCities"); // finish the sortCities foreach($options as $stateattr => $info){ echo '<option value="'.$info->code.'">'.$info->location.'</option>'."\n"; } echo '</optgroup>'."\n"; } else { //empty nodes don't do squat } } } ?> This is the array that: print_r($sortedStates); prints out: Array ( [0] => SimpleXMLElement Object ( [@attributes] => Array ( [statename] => Maryland ) [info] => Array ( [0] => SimpleXMLElement Object ( [code] => s5 [location] => Mount Laurel ) [1] => SimpleXMLElement Object ( [code] => f0 [location] => Baltimore ) [2] => SimpleXMLElement Object ( [code] => h4 [location] => Annapolis ) ) ) [1] => SimpleXMLElement Object ( [@attributes] => Array ( [statename] => Mississippi ) [info] => Array ( [0] => SimpleXMLElement Object ( [code] => a1 [location] => Jackson ) [1] => SimpleXMLElement Object ( [code] => d2 [location] => Gulfport ) [2] => SimpleXMLElement Object ( [code] => g6 [location] => Hattiesburg ) ) ) [2] => SimpleXMLElement Object ( [@attributes] => Array ( [statename] => Texas ) [info] => Array ( [0] => SimpleXMLElement Object ( [code] => i9 [location] => Dallas ) [1] => SimpleXMLElement Object ( [code] => a7 [location] => Austin ) ) ) ) this: // start the sortCities function sortCities($a, $b){ return strcmp($a->location, $b->location); } plus this part of code: $options = array(); foreach($stateattr->info as $info) { $options[] = $info; } usort($options, "sortCities"); // finish the sortCities foreach($options as $stateattr => $info){ echo '<option value="'.$info->code.'">'.$info->location.'</option>'."\n"; } is doing a fine job of sorting by the 'location' node within each optgroup. You can see that in the array I can make it sort by the attribute 'statename'. What I am having trouble with is echoing out and combining the two functions in order to have it auto sort both the states and the cities within and forming the needed optgroups. I tried copying the lines for the cities and changing the names called several ways to no avail.

    Read the article

1 2 3 4 5 6  | Next Page >