simplexml

Using simplexml_load_file to pull from tumblr - timing out every time

若如初见. 提交于 2019-12-02 19:35:50
问题 My site is taking ~45 seconds to load. It's because I'm pulling in some XML from tumblr, but I can't figure out if this is my server's fault, tumblr's fault, or some other factor. Can I get this script to time out in 5 seconds and echo 'tumblr is down'; instead of just timing out after nearly a minute? I'm getting this error: Warning: simplexml_load_file(http://blog.yaytalent.com/api/read?type=post&start=1&num=2) [function.simplexml-load-file]: failed to open stream: Connection timed out in

Resolve namespaces with SimpleXML regardless of structure or namespace

浪子不回头ぞ 提交于 2019-12-02 19:22:28
问题 I got a Google Shopping feed like this (extract): <?xml version="1.0" encoding="utf-8" ?> <rss version="2.0" xmlns:g="http://base.google.com/ns/1.0"> ... <g:id><![CDATA[Blah]]></g:id> <title><![CDATA[Blah]]></title> <description><![CDATA[Blah]]></description> <g:product_type><![CDATA[Blah]]></g:product_type> Now, SimpleXML can read the "title" and "description" tags but it can't read the tags with "g:" prefix. There are solutions on stackoverflow for this specific case, using the "children"

SimpleXML keeps returning content on CDATA element

 ̄綄美尐妖づ 提交于 2019-12-02 18:53:38
问题 So another CDATA returning content question. I've seen many answers, but even though I tried them all, I still get only content. In more details: I have an xml file (containing many NewsItem inside): <NewsML> <NewsItem> <NewsComponent> <ContentItem> <DataContent> <body> <body.content> <![CDATA[<p>This is what I am trying to retrieve</p>]]> </body.content> </body> </DataContent> </ContentItem> </NewsComponent> </NewsItem> I am trying to get the content of body.content. Here is my code: $xml =

DOM with SimpleXML Doesnt show the data in XML format in Browser using PHP

给你一囗甜甜゛ 提交于 2019-12-02 18:52:26
问题 This is my PHP code to read XML from a URL using SimpleXML and DOM to change some parameters and show it on a web page The Feed i am reading is at http://tinyurl.com/boy7mr5 <?php $xml = simplexml_load_file('http://www.abc.com'); $doc = new DOMDocument(); $doc->formatOutput = true; $r = $doc->createElement( "All_Products" ); $doc->appendChild( $r ); foreach( $xml as $Product) { $b = $doc->createElement( "Product" ); $doc->appendChild( $b ); foreach($Product as $prname=>$value) { $prname1 =

PHP CURL - how to tell if the entire file requested was not fully downloaded

╄→尐↘猪︶ㄣ 提交于 2019-12-02 18:31:25
问题 I'm using CURL and a proxy to grab some xml files, occasionally only part of the XML document comes through and fails when I try to load/use the xml (simplexml_load_string). I thought something like.. if(curl_errno($ch)) { $error = curl_error($ch); // handle error } would catch this sorta error via CURL errno.. CURLE_PARTIAL_FILE (18) A file transfer was shorter or larger than expected. This happens when the server first reports an expected transfer size, and then delivers data that doesn't

php: export array to xml trouble

眉间皱痕 提交于 2019-12-02 18:15:15
问题 I have an array which I need to convert to XML with SimpleXML. The method below is almost doing the work but there's one trouble with it. It can't generate structure like this: $xmlFields = array( 'rootElt' => array( 'field1' => '', 'field2' => '', 'field3' => array( 'field4' => array( 'income' => array( 'owner' => '', 'description' => '', ), 'income' => array( 'owner' => '', 'description' => '', ), ), ) ) ); It writes only the last 'income' of section 'field4' but I need the output like:

simpleXMLElement attributes and foreach

自闭症网瘾萝莉.ら 提交于 2019-12-02 17:33:39
问题 If I run in the debugger, the program performs just 2 iterations correctly, and then do an infinite loop. If I exchange the line with foreach, it works correctly. Why? test.xml: <?xml version="1.0" encoding="utf-8"?> <response result="0"> <reports> <get count="2"> <row a="first" b="second" comment="test" c=""/> <row a="first1" b="second2" comment="test2" c=""/> </get> </reports> </response> PHP: $xml = simplexml_load_file('test.xml'); $rows = $xml->xpath('reports/get/row'); foreach($rows as

Can't read XML with simplexml_load_file PHP

旧街凉风 提交于 2019-12-02 16:35:18
问题 So i am trying to parse data from an XML url and insert it into a table using php, which can be seen here, (please keep in mind there are more products than displayed on this page, i am not trying to get it for just this Product,the code below shows how i am parsing all products) but i keep getting the following errors: [EDITED] class DataGrabber { //The URL where data will be extracted from, which is an XML file protected $URL = "http://json.zandparts.com/api/category/GetCategories/44/EUR/";

SimpleXMLElement file does not load xmlString

天涯浪子 提交于 2019-12-02 15:52:47
问题 I am trying to work on an XML Based problem. So far, it's proving to be a bummer for some reason. My code is only two lines and for some reason nothing is loading in. The code: $xmlString = file_get_contents('file.xml'); $xmlObject = simplexml_load_string($xmlString); // also in the above line I have tried // 1. new SimpleXMLElement('file.xml') // 2. simplexml_load_file('file.xml') The functions do not load, and this I can tell by var_dumping $xmlObject, which returns boolean false. file_get

Getting viewCount from XML [duplicate]

拈花ヽ惹草 提交于 2019-12-02 13:27:50
This question already has an answer here: Get XML Attribute with SimpleXML 3 answers I'm currently using the YouTube API form Google and I'm trying to get the "viewCount" array. I've tried this already with no luck at all. Here is the link that I'm currently using. I tried this before with no luck at all. $url = 'http://gdata.youtube.com/feeds/api/users/gudjondaniel/uploads?max-results=1'; $source = file_get_contents($url); $xml = new SimpleXMLElement($source); $title = $xml->entry->viewCount; Any help is greatly appreciated. For other people: the OP wants to access the <yt:statistics