simplexml

XPath Invalid Expression

<?php $feed = file_get_contents('http://thexmofo.wordpress.com/feed/'); $xml = new SimpleXMLElement($feed); $xml->registerXPathNamespace('media', 'http://thexmofo.wordpress.com/feed/'); $images = $xml->xpath('/rss/channel/item/media:content@url'); var_dump($images); ?> Can anyone tell my why I'm getting Warning: SimpleXMLElem...

How to save a neatly formatted XML file using Simple XML?

What's the "trick" to save an XML file that visually would result neatly formatted? such as: <xml> <item>foo</item> </xml> and not: <xml><item>foo</item></xml> ...

"Trying to get property of non-object" error with SimpleXML and PHP

I'm using a PHP script with SimpleXML to parse an XML feed. I have no control over the content of the XML. try { $xml = @new SimpleXMLElement($fetchResult); } catch (Exception $e) { errorHandle($e->getMessage());} $userNick = $xml->View->ScrollView->VBoxView->View->MatrixView->VBoxView[0]->HBoxView->TextView->SetFontStyle->b; ...

PHP SimpleXML - Remove xpath node

Hi, I'm a little confused as to how i can delete a parent node of something which i can find via an xpath search: $xml = simplexml_load_file($filename); $data = $xml->xpath('//items/info[item_id="' . $item_id . '"]'); $parent = $data[0]->xpath("parent::*"); unset($parent); So, it finds the item id, no problems there - but the unset is...

PHP simpleXML parsing

I need currency conversion, euro to dollar. The European Central bank provides the rates here: http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml I can get the USD rate by using the first node, but what if they change the order? Do I need something more reliable? I have no idea how.. $xml = @simplexml_load_file('http://www.ecb...

get parent elements in xml with simplexml in php?

with $element->children() i cant get all the child elements of current element. but how can i get all the parent elements for current element with simplexml? lets say it looks like this: <entity id=1> <name>apple</name> <entities> <entity id=2> <name>mac</name> <entities> <entity id=3> ...

PHP parsing XML file with and without namespaces

I need to get a XML File into a Database. Thats not the problem. Cant read it, parse it and create some Objects to map to the DB. Problem is, that sometimes the XML File can contain namespaces and sometimes not. Furtermore sometimes there is no namespace defined at all. So what i first got was something like this: <?xml version="1.0" e...

Problem parsing an atom feed using simplexml_load_file(), can't get an attribute.

Hi, I am trying to create a social timeline. I pull in feeds form certain places so I have a timeline of thing I have done. The problem I am having is with Google reader Shared Items. I want to get the time at which I shared the item which is contained in <entry gr:crawl-timestamp-msec="1269088723811"> Trying to get the element using $...

PHP: How do I loop through every XML file in a directory?

Hi! I'm building a simple application. It's a user interface to an online order system. Basically, the system is going to work like this: Other companies upload their purchase orders to our FTP server. These orders are simple XML files (containing things like customer data, address information, ordered products and the quantities…) I...

Parse RDF XML file to get all rdf:about values

I am using php's simple xml and xpath to parse an rdf xml file and am struggling to get a list of all the rdf:about values. Any advice? ...

SimpleXML - "Node no longer exists"

Hi 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 fin...

Error: "Input is not proper UTF-8, indicate encoding !" using PHP's simplexml_load_string

I'm getting the error: parser error : Input is not proper UTF-8, indicate encoding ! Bytes: 0xED 0x6E 0x2C 0x20 When trying to process an XML response using simplexml_load_string from a 3rd party source. The raw XML response does declare the content type: <?xml version="1.0" encoding="UTF-8"?> Yet it seems that the XML is not really ...

Loop not working when I try to traverse a Simple XML Object

I'm trying to loop through the results from the Last.fm API but it's not working. function get_url($url){ $ch = curl_init(); curl_setopt($ch,CURLOPT_URL,$url); curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,5); $content = curl_exec($ch); curl_close($ch); return $content; } ...

Sort/Group XML data with PHP?

I'm trying to make a page using data from the discogs.com (XML)-API. i've been parsing it with simpleXML and it's working pretty well but there is some things i'm not sure how to do. Here is part of the XML: <releases> <release id="1468764" status="Accepted" type="Main"> <title>Versions</title> <format>12", EP</format> <l...

SimpleDOM sortedXPath date sorting works on localhost but not on remote server.

Here's what i'm trying to do: 1) Take a basic XML page (data.xml) 2) Load it with simpleDOM 3) Use simpleDOM sortedXPath to sort all XML items by their pubDate 4) Display sorted output Here is the code I currently have. My code below outputs exactly what I need when run it on my localhost (XAMPP w/PHP 5.3) but on my remote server (which...

Loop XML including all its children using xpath and SimpleXMLElement

Im having a big xml tree with a simple structure. All I want to do is get a node by its attribute using xpath and loop the children. param1 - correct language param1 & param3 - correct node by its id and the parents id. (Need to use parent id when multiplie id appears. The id is not declared as id in DTD) public function getSubme...

Enumerate registered namespaces of a PHP DOMDocument object

Hello world, For one of my projects, I'm using the DOMDocument class to load and manipulate XML documents. I'd need to retrieve every namespace used in the document; however, I can't find how I'd do that. The DOMDocument class has methods to get the namespace prefix of an URI or the URI of a namespace prefix, but I've seen nothing to a...

Extracting data form XML file with SimpleXML in PHP

Introduction: I want to loop through XML files with flexible categories structure. Problem: I don't know to loop through a theoretical infinte subcategories without having to make x amount of "for each" statements (See coding example in the bottom). How do I dynamically traverse the categories structure? <?xml version="1.0" encoding=...

PHP: How to store XML data in an array?

Below is the XML I am working with - there are more items - this is the first set. How can I get these elements in to an array? I have been trying with PHP's SimpleXML etc. but I just cant do it. <response xmlns:lf="http://api.lemonfree.com/ns/1.0"&gt; <lf:request_type>listing</lf:request_type> <lf:response_code>0</lf:response_cod...

XPath query returning 'false' in SimpleXML

Hi all, I have an xml fragment as such: <meta_tree type="root"> <meta_data> <meta_cat>Content Provider</meta_cat> <data>Mammoth</data> </meta_data> <meta_data> <meta_cat>Genre</meta_cat> <data>Games</data> </meta_data> <meta_data> <meta_cat>Channel Name</meta_cat> <dat...