simplexml

How to traverse SimpleXML to edit text nodes?

匆匆过客 提交于 2019-12-20 06:19:28
问题 I need to implement the following algorithm with SimpleXML: put a XML fragment string into a SimpleXML object; traverse all the nodes, selecting text nodes; edit the text node (example convert to upper case); return the xml as string. PROBLEMS: How to load a XML with named entities (ex.   ). To traverse XML to get only text nodes... With $sx->xpath('//text()'); I can not edit the nodes, how to select text nodes to edition? 回答1: You can override the text content of a node returned by a

Reorder XML nodes with php and simplexml

醉酒当歌 提交于 2019-12-20 05:24:11
问题 My page is currently updating an existing xml, the problem is that when it adds new nodes they go to the end of the xml or parent tag ie: <N1></N1> <N1></N1> <N2></N2> <N2></N2> <N2></N2> <N1></N1> //I want this node to be displayed with the other N1 nodes. I have read solutions for this that don't use simplexml, but the problem is that I have already written way to much code around simplexml to change now. Also, keep in mind that the page isn't rewriting the xml from scratch, rather it is

Weird SimpleXML issue - can't reference nodes by name?

孤者浪人 提交于 2019-12-20 04:24:12
问题 I'm trying to parse a remote XML file, which is valid: $xml = simplexml_load_file('http://feeds.feedburner.com/HammersInTheHeart?format=xml'); The root element is feed , and I'm trying to grab it via: $nodes = $xml->xpath('/feed'); //also tried 'feed', without slash Except it doesn't find any nodes. print_r($nodes); //empty array Or any nodes of any kind, so long as I search for them by tag name, in fact: $nodes = $xml->xpath('//entry'); print_r($nodes); //empty array It does find nodes,

PHP simplexml_load_file catch 403

£可爱£侵袭症+ 提交于 2019-12-20 04:18:19
问题 I am using the following PHP: $xml = simplexml_load_file($request_url) or die("url not loading"); I use: $status = $xml->Response->Status->code; To check the status of the response. 200 bening everything is ok, carry on. However if I get a 403 access denied error, how do I catch this in PHP so I can return a user friendly warning? 回答1: To retrieve the HTTP response code from a call to simplexml_load_file() , the only way I know is to use PHP's little known $http_response_header . This

'getElement(s)By' in the PHP class SimpleXML like in PHP-DomDocument?

巧了我就是萌 提交于 2019-12-19 21:19:13
问题 I have made a application using DomDocument & SimpleXML, but the server doesn't support DomDocument (Only SimpleXML). Now I am rewriting it, but there aren't any functions in SimpleXML like "getElementsByTagName" and "getElementById" (I only need those 2). I have searched a lot on php.net & google.com, but can't find one. I am not that good to write my own. So, does anyone know a alternative/function/tip/script for me? :) Thanks in advance. 回答1: Happily, if SimpleXML doesn't support those DOM

'getElement(s)By' in the PHP class SimpleXML like in PHP-DomDocument?

自作多情 提交于 2019-12-19 21:18:35
问题 I have made a application using DomDocument & SimpleXML, but the server doesn't support DomDocument (Only SimpleXML). Now I am rewriting it, but there aren't any functions in SimpleXML like "getElementsByTagName" and "getElementById" (I only need those 2). I have searched a lot on php.net & google.com, but can't find one. I am not that good to write my own. So, does anyone know a alternative/function/tip/script for me? :) Thanks in advance. 回答1: Happily, if SimpleXML doesn't support those DOM

XML parsing using but Element Names are Dynamic

╄→гoц情女王★ 提交于 2019-12-19 11:56:06
问题 Simple XMLElement Object ( [IpStatus] => 1 [ti_pid_20642] => SimpleXmlElement Object ( I have a SimpleXMLElment in above format and this XML is generated at run time and it's node values like ti_pid_20642 are partly dnymaic, for example ti_pid_3232 , ti-pid_2323 , ti_pid_anyumber . My question is how can I get these nodes values and it's children using PHP? 回答1: To get all node names that are used in an XML string with SimpleXML you can use the SimpleXMLIterator : $tagnames = array_keys

PHP Simple HTML DOM Parser - Link element in RSS

末鹿安然 提交于 2019-12-19 09:27:15
问题 I just started using PHP Simple HTML DOM Parser (http://simplehtmldom.sourceforge.net/) and have some problems parsing XML. I can perfectly parse all the links from HTML documents, but parsing links from RSS feeds (XML format) doesn't work. For example, I want to parse all the links from http://www.bing.com/search?q=ipod&count=50&first=0&format=rss so I use this code: $content = file_get_html('http://www.bing.com/search?q=ipod&count=50&first=0&format=rss'); foreach($content->find('item') as

SOAP response to XML with SimpleXML

£可爱£侵袭症+ 提交于 2019-12-19 09:15:55
问题 I am trying to convert a SOAP response to XML. SOAP has an envelop and a body <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <soap:Body> When I try to convert $responseXML = simplexml_load_string($string); I get object(SimpleXMLElement)#20 (0) { } If I edit the $string as soap:Envelope and soap:Body I can get the XML. What's wrong with : ? Can not get XML. I hope it's

Can I use SimpleXML & Xpath to directly select an Elements Attribute?

拟墨画扇 提交于 2019-12-19 08:52:04
问题 i.e. - i want to return a string "yellow" using something like xpath expression "//banana/@color" and the following example xml... <fruits> <kiwi color="green" texture="hairy"/> <banana color="yellow" texture="waxy"/> </fruits> $fruits = simplexml_load_string( '<fruits> <kiwi color="green" texture="hairy"/> <banana color="yellow" texture="waxy"/> </fruits>'); print_r($fruits->xpath('//banana/@color')); produces Array ( [0] => SimpleXMLElement Object ( [@attributes] => Array ( [color] =>