simplexml

How can I check if a object is an instance of a specific class?

ⅰ亾dé卋堺 提交于 2019-12-19 06:21:22
问题 Is there a way to check if an object is an SimpleXMLELement ? private function output_roles($role) { foreach ($role as $current_role) { $role_ = $current_role->attributes(); $role_type = (string) $role_->role; echo "<tr>"; echo "<td><b>" . $role_type . "</b></td>"; echo "</tr>"; $roles = $role->xpath('//role[@role="Administrator"]//role[not(role)]'); if (is_array($roles)) { $this->output_roles($roles); } } } This is my function and the $role->xpath is only possible if the provided object is a

How can I check if a object is an instance of a specific class?

别说谁变了你拦得住时间么 提交于 2019-12-19 06:21:12
问题 Is there a way to check if an object is an SimpleXMLELement ? private function output_roles($role) { foreach ($role as $current_role) { $role_ = $current_role->attributes(); $role_type = (string) $role_->role; echo "<tr>"; echo "<td><b>" . $role_type . "</b></td>"; echo "</tr>"; $roles = $role->xpath('//role[@role="Administrator"]//role[not(role)]'); if (is_array($roles)) { $this->output_roles($roles); } } } This is my function and the $role->xpath is only possible if the provided object is a

Check if xml node exists in PHP [duplicate]

拟墨画扇 提交于 2019-12-19 05:23:11
问题 This question already has answers here : php SimpleXML check if a child exists (15 answers) Closed 5 years ago . I have this simplexml result object: object(SimpleXMLElement)#207 (2) { ["@attributes"]=> array(1) { ["version"]=> string(1) "1" } ["weather"]=> object(SimpleXMLElement)#206 (2) { ["@attributes"]=> array(1) { ["section"]=> string(1) "0" } ["problem_cause"]=> object(SimpleXMLElement)#94 (1) { ["@attributes"]=> array(1) { ["data"]=> string(0) "" } } } } I need to check if the node

Check if xml node exists in PHP [duplicate]

二次信任 提交于 2019-12-19 05:23:05
问题 This question already has answers here : php SimpleXML check if a child exists (15 answers) Closed 5 years ago . I have this simplexml result object: object(SimpleXMLElement)#207 (2) { ["@attributes"]=> array(1) { ["version"]=> string(1) "1" } ["weather"]=> object(SimpleXMLElement)#206 (2) { ["@attributes"]=> array(1) { ["section"]=> string(1) "0" } ["problem_cause"]=> object(SimpleXMLElement)#94 (1) { ["@attributes"]=> array(1) { ["data"]=> string(0) "" } } } } I need to check if the node

PHP/XML - how to read multible sub's

守給你的承諾、 提交于 2019-12-19 04:58:10
问题 I need a to create an array with all the subject values in this XML file. The ISIN list seems to work fine (the first property value), but subject values does not work. I would like to end up with a array looking something like this: $Companys = array ( [0] => array ( "isin" => "DK0010247014","company" => "AAB"), [1] => array ( "isin" => "DK0015250344","company" => "ALM BRAND"), [2] => array ( "isin" => "DK0015998017","company" => "BAVARIAN NORDI"), [3] => array ( "isin" => "DK0010259027",

simplexml_load_file not working “php_network_getaddresses: failed: Name or service not known”

帅比萌擦擦* 提交于 2019-12-19 04:56:10
问题 I started getting these warnings just recently, im not sure why, nor do i know how to fix it. What confuses me more, it was working before, i started working on another class and now i starting getting this error... im using linux fedora & apache for the webserver. Warning: simplexml_load_file() [function.simplexml-load-file]: php_network_getaddresses: getaddrinfo failed: Name or service not known in GetImagesFlickr.php on line 17 Warning: simplexml_load_file(http://api.flickr.com/services

How do I parse XML from PHP that was sent to the server as text/xml?

旧巷老猫 提交于 2019-12-19 04:39:44
问题 I have a client-side script written in jQuery that is sending text/xml data to the server, but I can't figure out how to parse the request since the data is not a query string variable. The jQuery looks like this: jQuery.ajax({ url: "test.php", type: "POST", processData: false, contentType: "text/xml", data: xmlDoc, success: function( data ) { alert( data ); } }); The xmlDoc is a valid XML document. I've tried everything in the PHP, but I can't get any of the nodes or content using simplexml.

How to replace XML node with SimpleXMLElement PHP

主宰稳场 提交于 2019-12-19 03:07:22
问题 I have the following XML (string1): <?xml version="1.0"?> <root> <map> <operationallayers> <layer label="Security" type="feature" visible="false" useproxy="true" usePopUp="all" url="http://stackoverflow.com"/> </operationallayers> </map> </root> And I have this piece of XML (string2): <operationallayers> <layer label="Teste1" type="feature" visible="false" useproxy="true" usePopUp="all" url="http://stackoverflow.com"/> <layer label="Teste2" type="dynamic" visible="false" useproxy="true"

How to convert SimpleXMLObject into PHP Array?

别来无恙 提交于 2019-12-18 18:53:29
问题 Consider the following code: $string = '<device> <id>1234</id> <label>118</label> <username>root</username> <password>helloWorld</password> <hardware> <memory>4GB RAM</memory> <storage_drives> <storage_drive_1>2TB SATA 7,200RPM</storage_drive_1> <storage_drive_2>1TB SATA 7,200RPM</storage_drive_2> <storage_drive_3>Not Applicable</storage_drive_3> <storage_drive_4>Not Applicable</storage_drive_4> </storage_drives> </hardware> </device>'; $xml = new SimpleXMLElement($string); $deviceDetails =

adding a new node in XML file via PHP

自作多情 提交于 2019-12-18 12:37:18
问题 I just wanted to ask a question .. how can i insert a new node in an xml using php. my XML file (questions.xml) is given below <?xml version="1.0" encoding="UTF-8"?> <Quiz> <topic text="Preparation for Exam"> <subtopic text="Science" /> <subtopic text="Maths" /> <subtopic text="english" /> </topic> </Quiz> I want to add a new "subtopic" with "text" attribute, that is "geography". How can i do this using PHP? Thanks in advance though. well my code is <?php $xmldoc = new DOMDocument(); $xmldoc-