simplexml

How do I create a duplicate of an XML element, but change the name of the element and delete the original? [duplicate]

久未见 提交于 2020-01-03 04:35:21
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: How do you rename a tag in SimpleXML through a DOM object? If I have an XML document like this: <document> <dogs> <bulldog>Blu</bulldog> <terrier>Benjie</terrier> </dogs> <cats> <tiger>Tiggger</tiger> <lion>Cowardly</lion> </cats> </document> And I want to reprint it, adding some attributes, but not keep the original.... <document> <canine type="fiction"> <bulldog>Blu</bulldog> <terrier>Benjie</terrier> </canine

Which is much faster, XMLParser or SimpleXML

偶尔善良 提交于 2020-01-02 06:08:52
问题 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. 回答1: 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

reading twitter's rss search feed with simple xml

烂漫一生 提交于 2020-01-01 07:23:43
问题 Having some trouble selecting some nodes in the rss feed for twitter's search the rss url is here http://search.twitter.com/search.rss?q=twitfile each item looks like this <item> <title>RT @TwittBoy: TwitFile - Comparte tus archivos en Twitter (hasta 200Mb) http://bit.ly/xYNsM</title> <link>http://twitter.com/MarielaCelita/statuses/5990165590</link> <description>RT <a href="http://twitter.com/TwittBoy">@TwittBoy</a>: <b>TwitFile</b> - Comparte tus archivos en Twitter (hasta 200Mb) <a href=

Problems getting XML content via https using SimpleXML and PHP [duplicate]

巧了我就是萌 提交于 2019-12-31 07:36:31
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: How to enable HTTPS stream wrappers I'm using simple XML to get content from an API. Usually I have no problems but now the URL is HTTPS it doesn't seem to work. Is there anyway around this? Example XML (url): <?xml version="1.0"?> <calendars> <calendar accommodation_id="1049165"> <day date="2012-08-09" vacancy="false" minimum_nights="7" arrival_day="true"/> <day date="2012-08-10" vacancy="false" minimum_nights=

XPath and PHP: nothing works properly

£可爱£侵袭症+ 提交于 2019-12-31 04:52:32
问题 Here is my code: $XML = <<<XML <items> <item id="123"> <name>Item 1</name> </item> <item id="456"> <name>Item 2</name> </item> <item id="789"> <name>Item 3</name> </item> </items> XML; $objSimpleXML = new SimpleXMLElement($XML); print_r($objSimpleXML->xpath('./item[1]')); print "- - - - - - -\n"; print_r($objSimpleXML->xpath('./item[2][@id]')); print "- - - - - - -\n"; print_r($objSimpleXML->xpath('./item[1]/name')); Nothing really special: I am trying to extract some data via XPath . The

Delete node with simplexml

此生再无相见时 提交于 2019-12-31 04:38:07
问题 I have this xhtml : <?xml version="1.0" encoding="UTF-8"?> <html> <head> <meta charset="utf-8"></meta> </head> <body> <nav> <ol> <li> <a href="cover.xhtml">Cover</a> </li> <li> <a href="page002.xhtml">P002</a> </li> <li> <a href="page005.xhtml">P005</a> </li> <li> <a href="page038.xhtml">P038</a> </li> </ol> </nav> </body> </html> I do this in php : copy("nav.xhtml", "nav.xml"); $doc1 = simplexml_load_file("nav.xml"); foreach($doc1->body->nav->ol->li->a as $seg){ $dom=dom_import_simplexml(

Simple math with decimals in PHP

こ雲淡風輕ζ 提交于 2019-12-31 03:06:10
问题 This is killing me! I've never had so much trouble and I can't figure out what I'm doing wrong here. If I have a number, say 2.32, and I want to do math with it it won't work out. The very simplest example: $income = $commission; //Commission is 2.32, retrieved from XML echo "income: $income<br>"; $income100 = $income*100; echo "income100: $income100<br>"; The result I get is: income: 2.32 income100: 200 How can I use a decimal number accurately with math without it changing it? Thanks so

SimpleXML/PHP - Can't access object

ⅰ亾dé卋堺 提交于 2019-12-31 01:53:29
问题 $tmp2 = '<?xml version="1.0"?><RWResponse><RESPONSE><DATA><HEADER><COLUMN>interval</COLUMN><COLUMN>name</COLUMN></HEADER></DATA></RESPONSE></RWResponse>'; $xml = simplexml_load_string($tmp2); echo $xml->RESPONSE->DATA->HEADER->COLUMN[0]; The above won't output anything, even though a var_dump is sucessful: object(SimpleXMLElement)#2 (1) { ["RESPONSE"]=> object(SimpleXMLElement)#3 (1) { ["DATA"]=> object(SimpleXMLElement)#4 (1) { ["HEADER"]=> object(SimpleXMLElement)#5 (1) { ["COLUMN"]=> array

Accessing certain properties of a SimpleXMLElement Object

和自甴很熟 提交于 2019-12-30 08:30:08
问题 When I print_r() the SimpleXMLElement Object referenced by variable $xmlObject , I see the following structure: SimpleXMLElement Object ( [@attributes] => Array ( [uri] => /example ) [result] => SimpleXMLElement Object ( [message] => Record(s) added successfully [recorddetail] => Array ( [0] => SimpleXMLElement Object ... ) ) ) Notice how the $xmlObject->result->message property looks like it is just a string. However, if I do print_r($xmlObject->result->message) , I get the following:

How to import XML string in a php DOMDocument

天涯浪子 提交于 2019-12-30 02:21:32
问题 For exemple, i create a DOMDocument like that : <?php $implementation = new DOMImplementation(); $dtd = $implementation->createDocumentType ( 'html', // qualifiedName '-//W3C//DTD XHTML 1.0 Transitional//EN', // publicId 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-' .'transitional.dtd' // systemId ); $document = $implementation->createDocument('', '', $dtd); $elementHtml = $document->createElement('html'); $elementHead = $document->createElement('head'); $elementBody = $document->createElement(