simplexml

How can I move XML elements with PHP's SimpleXML?

扶醉桌前 提交于 2019-12-12 04:09:22
问题 How can I move an xml element elsewhere in a document? So I have this: <outer> <foo> <child name="a"/> <child name="b"/> <child name="c"/> </foo> <bar /> </outer> and want to end up with: <outer> <foo /> <bar> <child name="a"/> <child name="b"/> <child name="c"/> </bar> </outer> Using PHP's simpleXML. Is there a function I'm missing (appendChild-like)? 回答1: You could make a recusrive function that clones the attributes and children. There is no other way to move the children with SimpleXML

sort simplexml array

本小妞迷上赌 提交于 2019-12-12 03:19:01
问题 I have this simplexml array which i managed to get working from examples on google. now i have to sort the array. this is what i have. $url = 'http://api.trademe.co.nz/v1/Member/2128687/Listings/All.xml'; $xml = simplexml_load_file($url); foreach($xml->List->Listing as $list){ echo $list->EndDate; echo '<br/>'; } everything works as it should like that. i want to sort it by closest to end date. ive tried all the examples i can find and i just keep getting white screen of nothing. please help!

simplexml_load_file not loading [duplicate]

▼魔方 西西 提交于 2019-12-12 03:02:38
问题 This question already has answers here : Load gzipped XML file with simplexml_load_file() (3 answers) Closed 6 years ago . This link to an rss feed doesn't load with simplexml_load_file . Link: http://www.nationnews.com/site/feed The link is a valid RSS feed and no it isn't a permission problem everything else loads. 回答1: First of all you need to enable error logging and/or reporting to find out more. Also you can check some parameters from the return value and the remote request: $result =

foreach xml node return selected element

南笙酒味 提交于 2019-12-12 02:58:50
问题 How can I get only selected value from my xml cdata tag? So far with help in stackoverflow I can get all the <b> tags in a string $result = simplexml_load_file($url, 'SimpleXMLElement', LIBXML_NOCDATA); foreach ($result->channel->item as $item) { $desc = $item->description; $dom = new DOMDocument($desc); $dom->loadHTML($desc); $bold_tags = $dom->getElementsByTagName('b'); foreach($bold_tags as $b) { echo $b->nodeValue . "<br>"; } but it will echo out all data which are inside <b> , but I want

Having trouble getting Fogbugz API response into a SimpleXML object

天大地大妈咪最大 提交于 2019-12-12 02:29:06
问题 I'm trying to write a wrapper around the fogbugz API, starting with getting a login token. I don's seem to be able to get the token into my wrapper object. $url = "http://..../fogbugz/api.asp?cmd=logon&email=" . $_UN . "&password=" . $_PW; $contents = file_get_contents($url); $resp = simplexml_load_file($contents); print_r($resp); Response is: SimpleXMLElement Object ( [token] => SimpleXMLElement Object ( ) ) The object in the token member var is empty. The response string however is OK. If I

Why aren't these values being added to my array as strings?

可紊 提交于 2019-12-12 01:58:30
问题 Further to my question here, I'm actually wondering why I'm not getting strings added to my array with the following code. I get some HTML from an external source with this: $doc = new DOMDocument(); @$doc->loadHTML($html); $xml = @simplexml_import_dom($doc); // just to make xpath more simple $images = $xml->xpath('//img'); $sources = array(); Here is the images array: Array ( [0] => SimpleXMLElement Object ( [@attributes] => Array ( [alt] => techcrunch logo [src] => http://s2.wp.com/wp

simplexml_load_string loses the order of tags

限于喜欢 提交于 2019-12-12 01:52:59
问题 I have the following XML: <mobapp> <form> <input type="text" name="target" id="target" value="" maxlength="8" required="true" pattern="[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]"/> <label for="target"> Phone number</label> <input type="number" name="amount" id="amount" min="0" maxlength="16" required="true"/> <label for="amount"> Amount to load:</label> </form> </mobapp> When I use simplexml_load_string($theXML) I get the following: object(SimpleXMLElement)#150 (3) { ["input"]=> array(2) { [0]

Easy PHP SimpleXML Issue

谁都会走 提交于 2019-12-12 01:35:37
问题 I've got a really bad brain block with this. My XML file looks like this: <?xml version="1.0" encoding="UTF-8"?> <data> <fruits> <item>Apple</item> <item>Orange</item> <item>Banana</item> </fruits> <vegetables> <item>Lettuce</item> <item>Carrot</item> </vegetables> </data> I am tyring to use SimpleXML to retrieve an array containing "Apple, Orange, Banana". The code I am using is as follows: $xml=simplexml_load_file('food.xml'); foreach($xml as $fruits=>$item) { $foodlist[] = $item; } print_r

Access value through parent attribute [duplicate]

匆匆过客 提交于 2019-12-12 01:30:00
问题 This question already has answers here : XML with xpath and PHP: How to access the text value of an attribute of an entry (2 answers) SimpleXML: Selecting Elements Which Have A Certain Attribute Value (2 answers) Closed 6 years ago . I am looking to get the value A-1 through xpath based on a passed attribue. I have passed the index attribute of the unit through php from a previous page and am accessing it by global GET: $value = intval($_GET['index']); the xml: <UNIT index='1'> <ID>A-1</ID>

Select node based on attribute and change subnode

拟墨画扇 提交于 2019-12-12 01:19:55
问题 I have following XML file: <?xml version="1.0" encoding="UTF-8"?> <programmedata> <programme id="1"> <name>Left</name> <image_path></image_path> <rating_point>0</rating_point> <five_star>0</five_star> With following code I am trying to edit value of rating_point: $xml=simplexml_load_file("content.xml"); if(!empty($_POST["rating"]) && !empty($_POST["voted_programme"])){ try{ $rating = $_POST["rating"]; $i = $_POST['voted_programme']; $xml->programme[$i]->rating_point = $rating; if($rating ==