simplexml

simplexml_load_string errors on big files occur on one system but not another

三世轮回 提交于 2019-12-18 11:49:55
问题 I'm dealing with a third party PHP library that I can't edit, and it's been working fine for almost a year. It uses simplexml_load_string on the response from a remote server. Lately it's been choking on large responses. This is a data feed for real estate listings, and the format looks something like this: <?xml version="1.0"?> <RETS ReplyCode="0" ReplyText="Operation Successful Reference ID: 9bac803e-b507-49b7-ac7c-d8e8e3f3aa89"> <COUNT Records="9506" /> <DELIMITER value="09" /> <COLUMNS>

Problem with simpleXML and entity not being defined

左心房为你撑大大i 提交于 2019-12-18 09:26:24
问题 I'm trying to parse a XML file, but when loading it simpleXML prints the following warning: Warning: simplexml_load_file() [function.simplexml-load-file]: gpr_545.xml:55: parser error : Entity 'Oslash' not defined in import.php on line 35 This is that line: <forenames>BØIE</forenames><x> </x> As it is a warning, I might ignore it, but I'd like to understand what is happening. 回答1: HTML Encoding of Latin1 characters (like Ø, what that character describes) is what has broken the XML parser. If

simplexml_load_string() doesn't like foreign languages

≯℡__Kan透↙ 提交于 2019-12-18 09:19:15
问题 I am receiving an XML response which comes through perfectly. Words such as "português" and "españa" are correctly formatted. However, once I have parsed the XML through the php function simplexml_load_string() , the words are transformed as follows: "portugu�s" and "espa�a". 回答1: Simple XML always treats text internally as UTF-8 encoded, converting to and from this character set if necessary. To solve your issue either make sure that all output from your app is UTF-8 encoded or convert it to

Unable to parse xml data with colon (:) from response using getNamespaces()

荒凉一梦 提交于 2019-12-18 08:58:37
问题 I want to read whatever is inside the <q:content></q:content> tags in the following xml - $xml = '<?xml version="1.0"?> <q:response xmlns:q="http://api-url"> <q:impression> <q:content> <html> <head> <meta name="HandheldFriendly" content="True"> <meta name="viewport" content="width=device-width, user-scalable=no"> <meta http-equiv="cleartype" content="on"> </head> <body style="margin:0px;padding:0px;"> <iframe scrolling="no" src="http://some-url" width="320px" height="50px" style="border:none;

PHP parsing a georss namespace with simpleXML

血红的双手。 提交于 2019-12-18 08:51:09
问题 Trying to parse out lat/lon from a google maps rss feed: $file = "http://maps.google.com/maps/ms?ie=UTF8&hl=en&vps=1&jsv=327b&msa=0&output=georss&msid=217909142388190116501.000473ca1b7eb5750ebfe"; $xml = simplexml_load_file($file); $loc = $xml->channel->item; echo $loc[0]->title; echo $loc[0]->point; The title shows up alright, but point gives me nothing. Each node looks like this: <item> <guid isPermaLink="false">0004740950fd067393eb4</guid> <pubDate>Sun, 20 Sep 2009 21:47:49 +0000</pubDate>

Set time out on simplexml_load_file

夙愿已清 提交于 2019-12-18 08:24:58
问题 I have this script which outputs an rss feed. Want I want to do is have it attempt to reach the rss url for something like 5 sec tops, and if it cannot then I want it to load a backup xml doc that is on the server. This is what I have and it is not working: <?php include '../php/connect.php'; $metaData = mysql_query("SELECT * FROM `siteinfo`") or die("couln't find table :("); $displayData = mysql_fetch_assoc($metaData); $url = $displayData['status']; $xml = file_get_contents($url); stream_set

Retrieving a subset of XML nodes with PHP

帅比萌擦擦* 提交于 2019-12-18 07:10:55
问题 Using PHP, how do I get an entire subset of nodes from an XML document? I can retrieve something like: <?xml version="1.0" encoding="utf-8"?> <people> <certain> <name>Jane Doe</name> <age>21</age> </certain> <certain> <certain> <name>John Smith</name> <age>34</age> </certain> </people> But what if I only want to return the child nodes of like this? <certain> <name>Jane Doe</name> <age>21</age> </certain> <certain> <certain> <name>John Smith</name> <age>34</age> </certain> EDIT: I'm trying to

SimpleXML Attributes to Array

亡梦爱人 提交于 2019-12-18 03:09:52
问题 Is there any more elegant way to escape SimpleXML attributes to an array? $result = $xml->xpath( $xpath ); $element = $result[ 0 ]; $attributes = (array) $element->attributes(); $attributes = $attributes[ '@attributes' ]; I don't really want to have to loop through it just to extract the key/value pair. All I need is to get it into an array and then pass it on. I would have thought attributes() would have done it by default, or at least given the option. But I couldn't even find the above

PHP sorting issue with simpleXML

血红的双手。 提交于 2019-12-17 22:59:43
问题 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

PHP SimpleXML. How to get the last item?

陌路散爱 提交于 2019-12-17 21:14:26
问题 How would I get the last item (or any specific item for that matter) in a simplexml object? Assume you don't know how many nodes there will be. ex. <?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet type="text/xsl" href="/xsl.xml"?> <obj href="http://xml.foo.com/" display="com.foo.bar" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://obix.org/ns/schema/1.0" > <list name="data" of="HistoryRecord"> <obj> <abstime name="timestamp" val="1876-11-10T00:00:00-08:00"></abstime