simplexml

Simplexml_load_string($string) returns an empty object but $string contains xml? code below

◇◆丶佛笑我妖孽 提交于 2019-12-09 02:34:55
问题 I retrieve some information using cURL in xml format. .... $xml = curl_exec($ch); $data = simplexml_load_string($xml); print_r($data); //out put - SimpleXMLElement Object ( ) if I try - print_r($xml); and view page source I get <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <ns7:users xmlns="http://www.example.com/xml/ns/rs" xmlns:ns2="http://www.example.com/xml/ns/users" xmlns:ns3="http://www.example.com/2004/11/tHistory" xmlns:ns4="http://www.example.com/fsi/tHistory" xmlns:ns5=

Reading text in `<![CDATA[…]]>` with SimpleXMLElement [duplicate]

一笑奈何 提交于 2019-12-09 00:52:20
问题 This question already has answers here : Getting cdata content while parsing xml file (3 answers) Closed 5 years ago . I'm importing an RSS feed with SimpleXMLElement in PHP. I'm having trouble with the title and description. For some reason, the website I get the feed from puts the title and description in <![CDATA[...]]> : <item> <title><![CDATA[...title...]]></title> <link>...url...</link> <description><![CDATA[...title...]]></description> <pubDate>...date...</pubDate> <guid>...link...<

How do I obtain an iterative object reference to the root object in PHP?

六眼飞鱼酱① 提交于 2019-12-08 16:53:35
问题 I have a class that takes some basic HTML5 and with some DOM magic turns it into a class which is an extension simpleXMLElement. This all starts at a "factory" (I might be abusing that term slightly) class called XPage. Thus we might have <?php $MyPage = new XPage($HTML); So far so good. What I now need to do is select some parts of the XML doc so that they can be "bookmarked" (I am sure that there is a better name for it) so one can go like this $MyPage->ThatBit("foo")->addChild('p',

Merge two XML files recursively

泪湿孤枕 提交于 2019-12-08 16:47:34
问题 I want to merge 2 XML files into one recursively. For example : 1st file : <root> <branch1> <node1>Test</node1> </branch1> <branch2> <node>Node from 1st file</node> </branch2> </root> 2nd file : <root> <branch1> <node2>Test2</node2> </branch1> <branch2> <node>This node should overwrite the 1st file branch</node> </branch2> <branch3> <node> <subnode>Yeah</subnode> </node> </branch3> </root> Merged file : <root> <branch1> <node1>Test</node1> <node2>Test2</node2> </branch1> <branch2> <node>This

How to extract the content of <uri></uri> in a XML document?

那年仲夏 提交于 2019-12-08 13:54:07
问题 I have a document that it's structure is like below. There are a lot of <entry> . My question is how can I output the <uri> of each entry? And another question, how can I output only the USERNAME ? This is the file I want to get the usernames http://search.twitter.com/search.atom?q=yankees <?xml version="1.0" encoding="UTF-8"?> <feed xmlns:google="http://base.google.com/ns/1.0" xml:lang="en-US" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/" xmlns="http://www.w3.org/2005/Atom" xmlns

Php Xpath query returning “Array”

耗尽温柔 提交于 2019-12-08 11:55:53
问题 ive got my xml file and also heres my php script $db = simplexml_load_file("BIN/videos.xml"); $id = $_GET['id']; $tq = "//video['@id=" . $id . "']/title[0]"; $dq = "//video['@id=" . $id . "']/description[1]"; $eq = "//video['@id=" . $id . "']/embed[2]"; $title = $db->xpath($tq); $description = $db->xpath($dq); $embed = $db->xpath($eq); include("design/lyt.php"); echo $embed . '<br> <h1>' . $title . '</h1> <p>' . $description . '</p>'; ?> Its supposed to display "Test" for them all! but it

PHP Simplexml_Load_File fails

做~自己de王妃 提交于 2019-12-08 07:20:59
问题 I have successfully been able to get a pubmed results page in xml format and write the contents to a local file "Publications.xml". The problem is when I use simplexml_load_file("Publications.xml"), it fails. Not able to figure out why. <?php $feed = 'http://www.ncbi.nlm.nih.gov/pubmed?term=carl&sort=pubdate&report=xml'; $local = 'Publications.xml'; $curtime = time(); $filemodtime; if( (!file_exists($local)) || (time() - filemtime($local)) > 86400 ) { $contents = file_get_contents($feed); $fp

SimpleXML & PHP: Extract part of XML document & convert as Array

冷暖自知 提交于 2019-12-08 07:06:28
问题 Consider the following XML: <?xml version="1.0" encoding="UTF-8"?> <OS> <data> <OSes> <centos> <v_5> <i386> <id>centos5-32</id> <name>CentOS 5 - 32 bit</name> <version>5</version> <architecture>32</architecture> <os>centos</os> </i386> <x86_64> <id>centos5-64</id> <name>CentOS 5 - 64 bit</name> <version>5</version> <architecture>64</architecture> <os>centos</os> </x86_64> </v_5> <v_6> <i386> <id>centos6-32</id> <name>CentOS 6 - 32 bit</name> <version>6</version> <architecture>32</architecture

How does Simple XML use the [] operator?

可紊 提交于 2019-12-08 06:38:31
问题 In PHP you can use square brackets on an element to access attributes: $node = /* SimpleXMLElement */ $id = $node['id']; What's weird is that $id isn't a string, It's another SimpleXMLElement . Why isn't it a string? I find myself using strval() all over the place on this. How are the square brackets working? Can I do that with my own classes? I Haven't seen anything in the docs about this. 回答1: You can provide Array like access to your object by implementing the ArrayAccess interface, which

PHP Parse Soap Response Issue - SimpleXMLElement

随声附和 提交于 2019-12-08 05:00:33
问题 I'm having problems using PHP SimpleXMLElement and simpleSMLToArray() function to parse a SOAP Response. I'm getting the SOAP response from my SOAP Server just fine. I'm writing both the SOAP Client and Server in this case. I'm using NuSoap for the server. To me, the soap response looks perfect, but the PHP5 Soap Client doesn't seem to parse it. So, as in the past, I'm using SimpleXMLElement and the function simpleXMLToArray() from PHP.NET (http://php.net/manual/en/book.simplexml.php), but