simplexml

Go directly to simplexmlelement without xpath php

自作多情 提交于 2019-12-25 04:39:22
问题 Still very new to php... I have a large simplexmlstring and i want to get all the lastnames from the file and in which article they where: something like: article number 0 author position 0 'van Tricht' article number 0 author position 1 'Nieman' article number 0 author position 2 'van Tricht' article number 0 author position 3 'Bour' ..... article number 1 author position 0 'van Tricht' article number 1 author position 1 'Nieman' article number 1 author position 2 'van Tricht' article number

SimpleXML is not parsing my epp XML messages

安稳与你 提交于 2019-12-25 04:22:22
问题 I am trying to extract information out of a return xml epp messages from SIDN But i am not abbel to get some of the variables out of this messages. I manage to get the result code and messages. $domaininfo = xml messages that can be seen at : http://pastebin.com/HbXMkdD3 $xml = new SimpleXMLElement($domeininfo); // check result code if (isset($xml->response->result)) { foreach($xml->response->result->attributes() as $name => $value) { if ($name === 'code') { $code = $value; } } } if ($code ==

PHP SimpleXml - Retrieving attributes of namespaced children

感情迁移 提交于 2019-12-25 02:34:13
问题 I'm parsing an external Atom feed, some entries have a collection of namespaced children - I'm failing to retrieve attributes from those children. Abbreviated example: $feed = <<<EOD <feed xmlns="http://www.w3.org/2005/Atom" xmlns:ai="http://activeinterface.com/thincms/2012"> <entry> <title>Some Title</title> <ai:image>path/to/some/image</ai:image> <ai:ocurrence dateid="20120622" date="Fri, June 22, 2012" time="6:00 pm" /> <ai:ocurrence dateid="20120720" date="Fri, July 20, 2012" time="6:00

Removing an xml node using php

喜夏-厌秋 提交于 2019-12-25 02:15:38
问题 I have an xml file like this: <uploads> <upload> <name>asd</name> <type>123</name> </upload> <upload> <name>qwe</name> <type>456</name> </upload> </uploads> Now I want to delete a node upload that has a name child as (say qwe ). How can I delete it using php , so that the resulting xml is <uploads> <upload> <name>asd</name> <type>123</name> </upload> </uploads> I do not have too much knowledge about xml and related techniques. Is it possible to do it using xpath, like this $xml->xpath('/

Preserving line breaks in xml node

ぐ巨炮叔叔 提交于 2019-12-25 01:48:55
问题 I'm trying to convert lines in an XML node into an unordered list, however I'm having some difficulty. Take for example this node : <test> Line1 Line2 Line3 </test> I would like to transform it into this with PHP <ul> <li>Line1</li> <li>Line2</li> <li>Line3</li> </ul> I've tried using DOMDocument and SimpleXML, however neither seem to retain the newlines. When echoed, the node value looks like this : Line1 Line2 Line3 I've also tried explode in order to have an array containing each line as

How can I change the name of an XML tag with PHP/SimpleXML?

妖精的绣舞 提交于 2019-12-25 01:26:27
问题 With SimpleXML, it is possible to add/change/delete attributes of a selected Node «on the fly» by typing e.g. $child->addAttribute('n', $occ_order); is there a way to alter the name of the $child element as well? I would expect something like $child->setName('newTagName'); but I cannot find a corresponding function in the API. Thanks in advance for your hints! 回答1: From the docs[1] it looks like you can't. And it would be kind of weird if you could too - changing the name makes it a different

How can i get to xml attribute of <yt:accesscontrol>?

坚强是说给别人听的谎言 提交于 2019-12-24 20:22:35
问题 I can't figure out or find out how to parse the permission="allowed" value out of this xml, using PHP simplexml_load_file . the basic structure is <?xml version='1.0' encoding='UTF-8'?> <entry xmlns="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" xmlns:gd="http://schemas.google.com/g/2005" xmlns:yt="http://gdata.youtube.com/schemas/2007" gd:etag="W/"DkEDSH47eCp7I2A9WhJbEEQ.""> <yt:accessControl action="comment" permission="allowed" /> <yt:accessControl action=

PHP Parse XML response with many namespaces

折月煮酒 提交于 2019-12-24 15:42:34
问题 Is there a way to parse through an XML response in PHP, taking into account all namespaced nodes and convert it to an object or array without knowing all the node names? For example, converting this: <?xml version="1.0" encoding="ISO-8859-1"?> <serv:message xmlns:serv="http://www.webex.com/schemas/2002/06/service" xmlns:com="http://www.webex.com/schemas/2002/06/common" xmlns:att="http://www.webex.com/schemas/2002/06/service/attendee"> <serv:header> <serv:response> <serv:result>SUCCESS</serv

PHP function in XML?

為{幸葍}努か 提交于 2019-12-24 14:34:42
问题 Is it possible to write a PHP function in a XML <doThis> doThis(){ bang bang bang! } </doThis> and use simplexml_load_file to get the object with that function? $foo = simplexml_load_file($xmlAbove); $foo->doThis(); //bang bang bang! 回答1: Firstly, you should always consider the security implications of running "code" like this. If this XML file has remote origins, and you execute the code, then it might do anything. What about exec(rm -fR /some/important/path); ? Or a database call that

SimpleXML PHP - Change Value from any Node [duplicate]

佐手、 提交于 2019-12-24 12:08:19
问题 This question already has answers here : Updating a node value with PHP's simpleXML and xpath not working (3 answers) Closed 5 years ago . Normaly i find everything at stackoverflow what iam locking for. but now i need ur help. my example xml: <xml> <first> <change>Text to change</change> </first> <second> <change1>Text to change</change1> <change2>Text to change</change2> <change3>Text to change</change3> </second> </xml> Now i need to change the text from the change nodes. But this is a