simplexml

Add rss xmlns namespace definition to a php simplexml document?

我怕爱的太早我们不能终老 提交于 2019-12-10 10:51:29
问题 I'm trying to create an itunes-valid podcast feed using php5's simplexml: <?php $xml_string = <<<XML <?xml version="1.0" encoding="UTF-8"?> <channel> </channel> XML; $xml_generator = new SimpleXMLElement($xml_string); $tnsoundfile = $xml_generator->addChild('title', 'Main Title'); $tnsoundfile->addChild('itunes:author', "Author", ' '); $tnsoundfile->addChild('category', 'Audio Podcasts'); $tnsoundfile = $xml_generator->addChild('item'); $tnsoundfile->addChild('title', 'The track title');

Parse CDATA from a SOAP Response with PHP

China☆狼群 提交于 2019-12-10 10:10:57
问题 I'm trying to parse out the CDATA from a SOAP response using SimpleXML and Xpath. I get the output that I looking for but the output returned is one continuous line of data with no separators that would allow me to parse. I appreciate any help! Here is the SOAP response containing the CDATA that I need to parse: <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> <soapenv:Body> <ns1:getIPServiceDataResponse xmlns:ns1="http://ws.icontent.idefense.com/V3/2"> <ns1:return

Getting an array from object using SimpleXMLElement

廉价感情. 提交于 2019-12-10 10:09:05
问题 I'm having some problems getting the array in these objects. When I print_r(), the following code is printed. $message_object is the name of the object. SimpleXMLElement Object ( [header] => SimpleXMLElement Object ( [responsetime] => 2012-12-22T14:10:09+00:00 ) [data] => SimpleXMLElement Object ( [id] => Array ( [0] => 65233 [1] => 65234 ) [account] => Array ( [0] => 20992 [1] => 20992 ) [shortcode] => Array ( [0] => 3255 [1] => 3255 ) [received] => Array ( [0] => 2012-12-22T11:04:30+00:00

SimpleXML - Cannot get attributes of first tag

时间秒杀一切 提交于 2019-12-10 10:05:20
问题 I am trying to read the attributes of the first tag of an XML. Here's the XML structure <myxml timestamp="1301467801"> <tag1>value1</tag1> <tag2>value2</tag2> … </myxml> And here's how I try to get the timestamp attribute (tried 2 approaches, listing them both here, none works) $timestamp = $xml->myxml->attributes()->timestamp; //gives Node no longer exists warning if($xml->myxml && $xml->myxml->attributes()){ //Doesn't enter this loop $arr = $xml->myxml->attributes(); $timestamp = $arr[

Use XPath with PHP's SimpleXML to find nodes containing a String

岁酱吖の 提交于 2019-12-10 06:12:26
问题 I try to use SimpleXML in combination with XPath to find nodes which contain a certain string. <?php $xhtml = <<<EOC <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de" lang="de"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>Test</title> </head> <body> <p>Find me!</p> <p> <br /> Find me! <br /> </p> </body> </html> EOC; $xml = simplexml_load

PHP SimpleXML, how to set attributes?

旧巷老猫 提交于 2019-12-10 01:49:56
问题 if you've got something like, <hello id="1" name="myName1"> <anotherTag title="Hello"> </anotherTag> </hello> <hello id="2" name="myName2"> <anotherTag title="Hi"> </anotherTag> </hello> How to change the attributes of, for example, hello id 2, to name="William" ? Or the title hi to hello ? Thanks a lot for your atention, H' 回答1: Remember, your XML document has to have a root element: $xml = simplexml_load_string("<root>$string</root>"); $xml->hello[1]['name'] = 'John Doe'; $xml->hello[1]-

SimpleXML - “Node no longer exists”

橙三吉。 提交于 2019-12-10 01:23:06
问题 I'm trying to get the video data from this youtube playlist feed and add the interesting data to an array and use that later, but as you can see from the feed some videolinks are "dead" and that results in problems for my code. The error I get is "Node no longer exists" when I try to access $attrs['url']. I've tried for hours to find a way to check if the node exists before I access it but I have no luck. If anyone could help me to either parse the feed some other way with the same result or

How do I Convert jSON to XML

半世苍凉 提交于 2019-12-09 18:25:03
问题 Before I begin, I know there are a bunch of questions similar to this, but trust me, I read all, if not most of them. I tried a bunch of solutions, but none of them seem to work. I'm getting a blank "tree" as my result. Here is the code that I am using. $jSON = json_decode('array here'); function array2xml($array, $xml = false){ if($xml === false){ $xml = new SimpleXMLElement('<result/>'); } foreach($array as $key => $value){ if(is_array($value)){ array2xml($value, $xml->addChild($key)); }

Adding in new XML root node

蹲街弑〆低调 提交于 2019-12-09 05:47:29
I need to add in a new root node to the following XML <?xml version="1.0"?> <unit> <source> <id>ANCH02</id> <uri>http://www.hamiltonisland.biz/tabid/339/Default.aspx</uri> </source> </unit> to become <?xml version="1.0"?> <units> <unit> <source> <id>ANCH02</id> <uri>http://www.hamiltonisland.biz/tabid/339/Default.aspx</uri> </source> </unit> </units> How could I do this? It doesn't seem like SimpleXMLElement has this functionality. I have also looked at this DomNode example http://php.net/manual/en/domnode.insertbefore.php but it doesnt seem to be able to add in a new root node. This seem to

Parsing a xml file using simplexml and accessing properties

↘锁芯ラ 提交于 2019-12-09 03:23:42
问题 I am trying to parse a xml file which has this structure: <?xml version="1.0" encoding="UTF-8" ?> - <uclassify xmlns="http://api.uclassify.com/1/ResponseSchema" version="1.00"> <status success="true" statusCode="2000" /> - <readCalls> - <classify id="cls1"> - <classification> <class className="Arts" p="0.920034" /> <class className="Business" p="2.81823e-005" /> <class className="Computers" p="0.0040341" /> <class className="Games" p="0.00846496" /> <class className="Health" p="0.00203198" />