simplexml

Getting XML attributes in PHP

不问归期 提交于 2019-12-13 04:04:04
问题 Looked at a few other SO posts on this but no joy. I've got this code: $url = "http://itunes.apple.com/us/rss/toppaidapplications/limit=10/genre=6014/xml"; $string = file_get_contents($url); $string = preg_replace("/(<\/?)(\w+):([^>]*>)/", "$1$2$3", $string); $xml = simplexml_load_string($string); foreach ($xml->entry as $val) { echo "RESULTS: " . $val->attributes() . "\n"; but I can't get any results. I'm specifically interested in getting the ID value which would be 549592189 in this

Create an XML file in server using SimpleXML and JQuery Ajax

不想你离开。 提交于 2019-12-13 03:58:45
问题 I need some help, I hope someone can help me =) What I want to do surely can be accomplished but I'm doing something wrong: I want to create an XML file when I use an Ajax call. I got the following code (synthesized). Please note maybe this example doesn't work, it's just to exemplify: HTML <html> <head> <!-- JQuery 1.7 included --> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js" type="text/javascript"></script> </head> <body> <p>Create XML on server!</p> <form id=

select only one node and move on php

只愿长相守 提交于 2019-12-13 03:56:39
问题 I have a list of songs from Echonest API with Spotify URI but it adds many more songs then I need. I only need one of them not all of them but I want to keep on doing this 20 times. So I only want to get the first track inside the node and move on to the next. Here is the xml file I get the info from This is the PHP I use: <iframe src="https://embed.spotify.com/?uri=spotify:trackset:Playlist based on Rihanna:<?php $completeurl = "http://developer.echonest.com/api/v4/playlist/static?api_key

Add node to a XML variable and Save it

二次信任 提交于 2019-12-13 03:14:53
问题 i want to add the xml node i.e <name>B07BZFZV8D</name> to the XML variable before saving it. I want to add the 'name' node inside the 'Self' Element. #Previously i use to save it directly like this, $Response #this is the respnse from api $dom = new DOMDocument; $dom->preserveWhiteSpace = FALSE; $dom->loadXML($Response); ##saving in file $myfile = file_put_contents('data.xml', $Response.PHP_EOL , FILE_APPEND | LOCK_EX); 回答1: With DOM you use methods of the document object to create the node

php loop not working as expected

自作多情 提交于 2019-12-13 03:01:31
问题 I'm trying to swap all attribute id's at once from '$old' > '$new' then save the xml: $reorder = array( 9=>"8", 8=>"5", 7=>"4", 6=>"3", 5=>"0", 4=>"1", 3=>"9", 2=>"7", 1=>"2", 0=>"6" ); $objDOM = new SimpleXMLElement(some.xml, null, true); foreach ($reorder as $old => $new) { $picture = $objDOM->xpath('picture[@id="'.$old.'"]'); $picture[0]["id"] = $new; } echo $objDOM->asXML(); The result below (doesn't match Array $reorder) 3 > 9 9 > 6 8 > 8 7 > 2 6 > 3 5 > 5 4 > 4 0 > 0 1 > 1 7 > 2 It

Accessing a XML node directly via a key

99封情书 提交于 2019-12-13 02:20:30
问题 $xml = simplexml_load_file($xmlPath); $items = $xml->list->item; ... echo $items[$currentIndex]->asXML(); When I print out $currentIndex on each iteration, I get 0, 1, 2, 3, 4, etc. When I hard code $items[0]->asXML(); $items[1]->asXML(); $items[2]->asXML(); etc. I get the data I want. But when I loop like I do in the first code segment, it prints out items 0, 2, 4, etc. How is that possible and what could be causing this? Thanks, Ryan ADDED INFO: This is the main part of it: $totalItems = 45

How can I parse XML to get multiple text blocks with SimpleXML?

陌路散爱 提交于 2019-12-13 00:57:39
问题 I want to parse some XML that looks like this: <node> This is <child> blah </child> some <child> foo </child> text </node> How do I get access to the text node children in Simple XML? Can I access them in the correct order of text and element children? Do I need some other package for this? 回答1: I'd strongly recommend switching to the DOM functions over SimpleXML. I had an answer like this a while ago which wasn't very popular, but I still stand by it. The DOM functions are just so much

Simple XML Load File not working

你。 提交于 2019-12-13 00:44:51
问题 how come this isn't working: $url = "http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20html%20where%20xpath%3D%22%2F%2Fmeta%22%20and%20url%3D%22http://www.cnn.com%22&format=xml&diagnostics=false"; $xml = (simplexml_load_file($url)) I get multiple errors telling me the HTTP request failed. Ultimately I want to get the results from this file into an array eg Description = CNN.com delivers the latest breaking news etc. Keywords = CNN, CNN news, CNN.com, CNN TV etc. But this initial

PHP, simplexml, Delete: Please tell me why the first variant is not working

佐手、 提交于 2019-12-12 23:08:01
问题 I hope you can help me on this one: I want to delete an xml node via unset. I have two variants of how this could be done, but only one is working. Please tell me whats the difference or why only the second variant is working. So when using the first variant the print_r() function gives back the whole xml file with the image 'Hansio' that should have been deleted. But when using the second variant the image is deleted! (You can actually copy the whole php code into a file as well as the xml

how to access this child element - attribute in php simplexml

为君一笑 提交于 2019-12-12 23:04:32
问题 I want to access the 'url' attribute in the media:content element below. I am pretty sure this gives me the media:content, but I can not seem to get the url (see what I tried below): $theContent = $item->children('media', true)->content; xml : <item> <media:content type="image/jpeg" url="my url" /> </item> I have tried variations: $theURL = $item->children('media', true)->content['url']; and $mediaItem=$item->children('media', true)->content; $contentItem=$mediaItem->children('content', true)