simplexml

How to detect if content wasn't found in the feed URL using SimpleXML and PHP

喜夏-厌秋 提交于 2019-12-02 07:01:49
问题 How do you detect if this function is empty ? ( returns nothing ) function last_uploads() { for($i = 0; $i < 20; ){ error_reporting(E_ALL); $feedURL = 'http://gdata.youtube.com/feeds/api/users/youtube/uploads?max-results=5'; $sxml = simplexml_load_file($feedURL); foreach ($sxml->entry as $entry) { $media = $entry->children('media', true); $url = (string)$media->group->player->attributes()->url; $thumb = (string)$media->group->thumbnail->attributes()->url; $watch = (string)$media->group-

SimpleXML Dynamic element names

孤街醉人 提交于 2019-12-02 06:33:36
echo $xml->SLOT1->Effect; echo $xml->SLOT2->Effect; echo $xml->SLOT3->Effect; Is there a way to simplify this by using a for loop? I tried this but it echos nothing: for ($x = 1; $x <= 3; $x++) { echo $xml->SLOT[$x]->Effect; } You can use $xml->{"SLOT".$x}->Effect; for ($x = 1; $x <= 3; $x++) { echo $xml->{SLOT.$x}->Effect; } 来源: https://stackoverflow.com/questions/10662795/simplexml-dynamic-element-names

Sorting and grouping SimpleXML Data

自古美人都是妖i 提交于 2019-12-02 06:07:07
I am sorting & grouping publication data from an XML file. The methods I am currently using are working fine for the most part , although I feel like there is a more efficient way to do what I am trying to accomplish. Here is a sample of what the target nodes look like: <comic> <id>117</id> <mainsection> <series> <displayname>My Amazing Adventure</displayname> <sortname>My Amazing Adventure</sortname> </series> </mainsection> <issuenr>2</issuenr> <seriefirstletter> <displayname>M</displayname> <sortname>M</sortname> </seriefirstletter> </comic> Here are the current steps I am taking. Loading

Get children attributes using simplexml

前提是你 提交于 2019-12-02 06:03:36
The xml data looks like this: <feed> <entry> <abc:rank scheme="http://foo.bar">45</abc:rank> <abc:rank scheme="http://foo2.bar">88</abc:rank> </entry> <entry> <abc:rank scheme="http://foo.bar">125</abc:rank> <abc:rank scheme="http://foo2.bar">32</abc:rank> </entry> </feed> I am able to output all of these entries with this code: foreach($xml->entry[$i]->children('abc', true) as $a) { echo $a; } However, if I want to get the one with the content "88" in the first entry, something like foreach($xml->entry[$i]->children('abc', true) as $a) { if($a["scheme"] == "http://foo2.bar") echo $a; } does

simplexml_load_file with & (ampersand) in url with Solr

给你一囗甜甜゛ 提交于 2019-12-02 05:52:32
I am using Solr and have the following query which works fine from my browser: http://www.someipaddress.com:8983/solr/select?q=*&fq=shopid:40&start=0&rows=18&fq=manufacturer:"Bausch+%26+Lomb" In part of the return xml I see: <str>manufacturer:"Bausch & Lomb"</str> However when I try and get the above url using simplexml_load_file like this: $xml = simplexml_load_file("http://127.0.0.1:8983/solr/select?q=*&fq=shopid:40&start=0&rows=18&fq=manufacturer:\"Bausch+%26+Lomb\""); I get no results because Solr is being passed the manufacturer string that looks like this (from print_r): [str] => Array (

Delete node with simplexml

我只是一个虾纸丫 提交于 2019-12-02 05:36:56
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($seg); $dom->parentNode->removeChild($dom); } $doc1->asXml("nav.xhtml"); In result, just the fist is

Reorder XML nodes with php and simplexml

时光总嘲笑我的痴心妄想 提交于 2019-12-02 05:31:29
My page is currently updating an existing xml, the problem is that when it adds new nodes they go to the end of the xml or parent tag ie: <N1></N1> <N1></N1> <N2></N2> <N2></N2> <N2></N2> <N1></N1> //I want this node to be displayed with the other N1 nodes. I have read solutions for this that don't use simplexml, but the problem is that I have already written way to much code around simplexml to change now. Also, keep in mind that the page isn't rewriting the xml from scratch, rather it is simply changing what is different. So is what I'm asking possible? thanks. There's no way to re-order

XML with varying amount of child nodes for each parent node

喜你入骨 提交于 2019-12-02 05:19:11
So I have XML in the following format which I am reading from file 'test.xml' <XML> <Agent ID="ABC123"> <Property> <Code>XYZ</Code> <Name>Hotel 1</Name> </Property> <Property> <Code>237</Code> <Name>Hotel 2</Name> </Property> <Property> <Code>213</Code> <Name>Hotel 3</Name> </Property> </Agent> <Agent ID="DEF456"> <Property> <Code>333</Code> <Name>Hotel 4</Name> </Property> <Property> <Code>23423</Code> <Name>Hotel 5</Name> </Property> </Agent> <Agent ID="GHI789"> <Property> <Code>45345</Code> <Name>Hotel 6</Name> </Property> </Agent> </XML> I want to be able to output the above into the

XPath and PHP: nothing works properly

僤鯓⒐⒋嵵緔 提交于 2019-12-02 05:11:56
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 path must be a string to design a dynamic program which loads its data from a XML configuration file. When

How to save an XML file on the web server using PHP?

ⅰ亾dé卋堺 提交于 2019-12-02 04:44:27
问题 I am a beginner in PHP and I know nothing about XML manipulation. I am working on a Google CSE annotation XML shown below: <?xml version="1.0" encoding="UTF-8" ?> - <Annotations> - <Annotation about="http://sanspace.in/"> <Label name="_cse_byxamvbyjpc" /> </Annotation> - <Annotation about="http://blog.sanspace.in/"> <Label name="_cse_byxamvbyjpc" /> </Annotation> - <Annotation about="http://google.com/"> <Label name="_cse_exclude_byxamvbyjpc" /> </Annotation> </Annotations> I want achieve