simplexml

SimpleXMLElement cannot be found when working with namespaces

梦想与她 提交于 2019-12-03 10:30:41
I'm trying to create a Widget in Wordpress, and I'm running into an issue creating a SimpleXMLElement object. Here is the code: namespace GenieKnows_Search; class GenieKnows_Search_Widget extends \WP_Widget { //Constructor function __construct() { parent::__construct('genieknows_search_widget', 'GenieKnows_Search_Widget'); } //Irrelevant Code. Removed for readability. //Return the XML function retrieve_gk_xml() { $xml = new SimpleXMLElement($this->create_gk_xml(), 0, true); //Line 114 return $xml->xpath('/feed/results/sponsored/listing'); } } Here is the error: PHP Fatal error: Class

convert xml data into mysql insert/update query using php

醉酒当歌 提交于 2019-12-03 09:14:39
I am working on this project that basically reads the data from xml file and insert/update the data into mysql database. Here is the sample.xml file: <table name="movies"> <column name="movie_name">Titanic</column> <column name="dvd">40</column> <column name="blueray">5</column> <column name="netflix">4</column> <column name="amazon">3</column> </table> I break down the problem into: 1) Get the values from XML file. 2) Insert the extracted values into mysql database. I am able to work on insert the values to database, but the hard part is getting the values from xml making me crazy. Here is my

Bulletproofing SimpleXMLElement

☆樱花仙子☆ 提交于 2019-12-03 07:44:18
Everyone knows that we should always use DOM techniques instead of regexes to extract content from HTML, but I get the feeling that I can never trust the SimpleXML extension or similar ones. I'm coding a OpenID implementation right now, and I tried using SimpleXML to do the HTML discovery - but my very first test (with alixaxel.myopenid.com) yielded a lot of errors: Warning: simplexml_load_string() [function.simplexml-load-string]: Entity: line 27: parser error : Opening and ending tag mismatch: link line 11 and head in E:\xampplite\htdocs\index.php on line 6 Warning: simplexml_load_string()

SimpleXML vs DOMDocument performance

落花浮王杯 提交于 2019-12-03 07:30:22
I am building an RSS parser using the SimpleXML Class and I was wondering if using the DOMDocument class would improve the speed of the parser. I am parsing an rss document that is at least 1000 lines and I use almost all of the data from those 1000 lines. I am looking for the method that will take the least time to complete. SimpleXML and DOMDocument both use the same parser ( libxml2 ), so the parsing difference between them is negligible. This is easy to verify: function time_load_dd($xml, $reps) { // discard first run to prime caches for ($i=0; $i < 5; ++$i) { $dom = new DOMDocument();

PHP: Whats's the difference between the SimpleXMLElement() class and SimpleXML_load_string()?

落花浮王杯 提交于 2019-12-03 06:57:50
问题 I've seen alot of coders implement SimpleXML_load_string() instead of the SimpleXMLElement() class. Are there any benefits to using the former over the latter? I've read the PHP manual on simplexml. I couldn't manage to get a grasp on what it is. Any help and guidance (perhaps through examples) would be much appreciated. Thanks in advance. 回答1: simplexml_load_string() (as the name suggest) load xml from a string and returns an object of SimepleXMLElement . There is no difference between this

Getting viewCount from XML [duplicate]

折月煮酒 提交于 2019-12-02 23:37:31
问题 This question already has answers here : Get XML Attribute with SimpleXML (3 answers) Closed 6 years ago . I'm currently using the YouTube API form Google and I'm trying to get the "viewCount" array. I've tried this already with no luck at all. Here is the link that I'm currently using. I tried this before with no luck at all. $url = 'http://gdata.youtube.com/feeds/api/users/gudjondaniel/uploads?max-results=1'; $source = file_get_contents($url); $xml = new SimpleXMLElement($source); $title =

SimpleXML xpath within selected node

孤街浪徒 提交于 2019-12-02 22:20:46
问题 I have the following XML file <Item> <name>...</name> <id>...</id> <ImageSets> <ImageSet Category="variant"> <SwatchImage> <URL>...</URL> <Height Units="pixels"></Height> <Width Units="pixels"></Width> </SwatchImage> <SmallImage> <URL>...</URL> <Height Units="pixels"></Height> <Width Units="pixels"></Width> </SmallImage> </ImageSet> <ImageSet Category="primary"> <SwatchImage> <URL>...</URL> <Height Units="pixels"></Height> <Width Units="pixels"></Width> </SwatchImage> <SmallImage> <URL>...<

Unterminated entity reference in PHP

↘锁芯ラ 提交于 2019-12-02 21:42:17
Here is my code: <?php // 27/01/2016 Edit: $result = mysql_query("A Long mysql query"); $rss = new SimpleXMLElement('<rss version="2.0" />'); $products = $rss->addChild('products'); /// while($row = mysql_fetch_array($result)){ $product = $products->addChild('category'); $product->addChild('product_id',"$row[product_id]"); $product->addChild('cat_id',"$row[cat_id]"); $product->addChild('cat_name',"$row[cat_name]"); $product->addchild('product_code',"$row[product_code]"); $product->addchild('product_name',"$row[product_name]"); $product->addChild('description','$row[description]'); $product-

php simplexml issue in reading an attribute that has a 'column - : ' in its name

三世轮回 提交于 2019-12-02 21:19:18
问题 I have been trying to read an xml attribute that has a " : " in it, but I'm having trouble...specifically "yweather:condition" This is my code: if ($xml = simplexml_load_file("http://weather.yahooapis.com/forecastrss?p=LEXX0003&u=c")) { $namespacesMeta = $xml->getNamespaces(true); $yweather = $xml->children($namespacesMeta['yweather']); $docMeta = $yweather->{'condition'}; var_dump($docMeta); } i got here after reading off another thread on stackoverflow, but the result is not as I expected,

PHP: Whats's the difference between the SimpleXMLElement() class and SimpleXML_load_string()?

早过忘川 提交于 2019-12-02 20:36:14
I've seen alot of coders implement SimpleXML_load_string() instead of the SimpleXMLElement() class. Are there any benefits to using the former over the latter? I've read the PHP manual on simplexml . I couldn't manage to get a grasp on what it is. Any help and guidance (perhaps through examples) would be much appreciated. Thanks in advance. simplexml_load_string() (as the name suggest) load xml from a string and returns an object of SimepleXMLElement . There is no difference between this and using just the usual constructor of the class. Update: SimpleXML::__construct() has an additional