simplexml

PHP: send POST request then read XML response?

狂风中的少年 提交于 2019-12-05 19:12:10
I'm trying to write a PHP script that sends a POST request to a remote server, then parses the XML response. I can do the POST request, but am having difficulty (from other SO questions) working out how to parse the XML response. My current code gives me: Warning: simplexml_load_file() [function.simplexml-load-file]: I/O warning : failed to load external entity "1" in /Users/simon/usercreate.php on line 46 - the simplexml_load_file($response) line. I'm working on a local server, not sure if that makes a difference. Code: $curl = curl_init(); curl_setopt($curl, CURLOPT_URL,$url); curl_setopt(

Use XPath with PHP's SimpleXML to find nodes containing a String

江枫思渺然 提交于 2019-12-05 15:12:57
I try to use SimpleXML in combination with XPath to find nodes which contain a certain string. <?php $xhtml = <<<EOC <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de" lang="de"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>Test</title> </head> <body> <p>Find me!</p> <p> <br /> Find me! <br /> </p> </body> </html> EOC; $xml = simplexml_load_string($xhtml); $xml->registerXPathNamespace('xhtml', 'http://www.w3.org/1999/xhtml'); $nodes = $xml-

Which is much faster, XMLParser or SimpleXML

别等时光非礼了梦想. 提交于 2019-12-05 12:40:57
What do you think guys? I currently using SimpleXML for my entire project, which have average of 250KB in memory usage w/ 500micro seconds processing per execution. I just plan to switch to XMLParser, your advice is much appreciated. Edit : The actual microtime is 0.000578 micro seconds. Im just confused in milli and micro, lol. In most cases, XML Parser will be much slower both in terms of development and execution, mainly because you have to write/execute tons of userland PHP code to navigate/read your document. In some cases, you can find some improvement using XMLReader (not sure about XML

alternatives to simpleXML for parsing xml files with PHP

自作多情 提交于 2019-12-05 09:50:22
i just want to know if there are any alternatives to simpleXML for parsing XML Data with PHP. For example if simpleXML module is not loaded or even if there is a lib/class out there that has a better performance then SimpleXML. Obviously there's a ton of different way to process XML both as PHP extensions and userspace librairies. The problem is they are all much much more complicated than SimpleXML and nowhere as fast for random access. I'm not sure what's the goal of your question though. None of those libraries/extensions share a common API so if you want a fallback in case SimpleXML isn't

Call to undefined function simplexml_load_file()

≯℡__Kan透↙ 提交于 2019-12-05 09:31:07
I have php 7.0 running on my ubuntu server. php -m command says: [PHP Modules] calendar Core ctype curl date dom exif fileinfo filter ftp gd gettext hash iconv intl json libxml mbstring mcrypt mysqli mysqlnd openssl pcntl pcre PDO pdo_mysql Phar posix readline Reflection session shmop SimpleXML sockets SPL standard sysvmsg sysvsem sysvshm tokenizer wddx xml xmlreader xmlwriter xsl Zend OPcache zip zlib But still when I run my website, its log says " PHP Fatal error: Call to undefined function simplexml_load_file() " I had the same issue. I fixed it by installing php7.2-xml : $ apt-get install

Parsing google calendar XML feed

故事扮演 提交于 2019-12-05 09:02:42
I've got XML feed from public google calendar. Looks like this: <?xml version='1.0' encoding='UTF-8'?> <feed xmlns='................' xmlns:gd='http://schemas.google.com/g/2005'> <id>http://www.google.com/calendar/feeds/........./public/full</id> <updated>2009-08-24T10:57:00.000Z</updated> <category scheme='http://schemas.google.com/g/2005#kind' term='http://schemas.google.com/g/2005#event'/> <title type='text'>Sports Events</title> ..... <entry> <id>...........</id> <published>2009-08-14T00:29:58.000Z</published> <updated>2009-08-14T00:29:58.000Z</updated> <category scheme='http://schemas

php xpath problems

非 Y 不嫁゛ 提交于 2019-12-05 06:40:45
I am trying to parse a blogspot feed using xpath but it doesnt seem to be working with anything that I try. I am not sure if it is because of the namespaces or what but I was hoping someone could help me. Here is the code: $xml = simplexml_load_file('http://feeds.feedburner.com/blogspot/MKuf'); $next = $xml->xpath("//link[@rel='next']"); print_r($next); This is just returning an empty array and it should not be. I tried it doing just link or just entry and it still is returning empty. The only one I can run on it that works is *. Any help is appreciated. Like already said in the comment to you

Checking if an object attribute is set - SimpleXML

六眼飞鱼酱① 提交于 2019-12-05 06:22:25
I have some XML I am using PHP's SimpleXML class with and I have elements within the XML such as: <condition id="1" name="New"></condition> <condition id="2" name="Used"></condition> However they are not always there, so I need to check if they exist first. I have tried.. if (is_object($bookInfo->page->offers->condition['used'])) { echo 'yes'; } as well as.. if (isset($bookInfo->page->offers->condition['used'])) { echo 'yes'; } But neither work. They only work if I remove the attribute part. So how can I check to see if an attribute is set as part of an object? sesser What you're looking at is

PHP SimpleXML new line

隐身守侯 提交于 2019-12-05 05:27:49
I have created a XML file using PHP's simple XML, saved the file. When opening the file in php using fopen and printing the contents. my XML looks like this: (see below) <?xml version="1.0" encoding="UTF-8"?> <home><orderList><delivery_cost>0.00</delivery_cost><delivery_surname>TEST</delivery_surname><delivery_postcode>1234</delivery_postcode><status>1</status></orderList></home> I want the xml file looking all indented and on new lines for each element. Does anybody know how to do this? Thanks You can do this using the formatOutput property of DOMDocument . Save your XML like this instead,

Using PHP simpleXML to find a node I know the name of but not where it resides

余生颓废 提交于 2019-12-05 04:41:31
问题 I need to query an XML string in PHP were I know the names of the nodes I am looking for but I might not necessarily know the path to the node. I think I can do this with xpath but I can't work out how to set up a relative path to look anywhere in the document, could someone point me in the right direction. I am currently trying to acheive this with simpleXML, but if there is a better way of doing this I would love to hear it. 回答1: Don't use regexes to parse XML! The descendant (double-slash)