simplexml

Getting actual value from PHP SimpleXML node

Hey guys, $value = $simpleXmlDoc->SomeNode->InnerNode; actually assigns a simplexml object to $value instead of the actual value of InnerNode. If I do: $value = $simpleXmlDoc->SomeNode->InnerNode . "\n"; I get the value. Anyway of getting the actual value without the clumsy looking . "\n"? ...

SimpleXML more tags in 1 element

Hey guys, I want to parse some xml but I don't know how I can get the same tags out of 1 element. I want to parse this: <profile> <name>john</name> <lang>english</lang> <lang>dutch</lang> </profile> So I want to parse the languages that john speaks. how can I do that ? ...

SimpleXML, associative arrays, and XPath

Hey everybody, I have a question about xpath and arrays. What I was wondering was if it is possible to use xpath on some simpleXML and have it return an associative array of node names and their values. For example, say I have the following XML: <element1 page="1">blah</element1> <element2 page="1">blah blah</element2> <element3 page=...

Is there a way to add a PHP SimpleXMLElement to another SimpleXMLElement?

The "addChild" method of SimpleXMLElement seems like it should be the right choice, but it apparently only takes strings representing the tagname of the new child. There's the object-ish notation for referencing nodes of the tree and setting them, e.g. $simpleXMLNode->child = value, but that only seems to work for simple text/numeric va...

Best way to process large XML in PHP

I have to parse large XML files in php, one of them is 6.5 MB and they could be even bigger. The SimpleXML extension as I've read, loads the entire file into an object, which may not be very efficient. In your experience, what would be the best way? ...

How to Extract the URL from A String in PHP?

I'm using PHP's "simplexml_load_file" to get some data from Flickr. My goal is to get the photo url. I'm able to get the following value (assigned to PHP variable): <p><a href="http://www.flickr.com/people/19725893@N00/"&gt;codewrecker&lt;/a&gt; posted a photo:</p> <p><a href="http://www.flickr.com/photos/19725893@N00/2302759205/" t...

Format output of $SimpleXML->asXML();

Possible Duplicate: PHP simpleXML how to save the file in a formatted way? Edit Yes, this is a duplicate. Voted to close. - Eli Hi All, The title pretty much says it all. If I have something like (from the php site examples): $xmlstr = <<<XML <?xml version='1.0' standalone='yes'?> <movies></movies> XML; $sxe = new SimpleXML...

PHP SimpleXML Group By Element Type

Ok here's my dilemma. I am looking for a way to consolidate the data in a group using SimpleXML in PHP. Here's what I mean. Let's say I have an xml that looks like this: <favorites> <interesting> <type>Movie</type> <character>James Bond</character> <name>Casino Royale</name> </interesting> <interes...

SimpleXMLElement PHP4

I know SimpleXMLElement doesn't work in PHP4, but is there a something similar I can replace it with to make the script work with PHP 4? ...

Remove namespace from XML using PHP

Hello everyone! I have an XML document that looks like this: <Data xmlns="http://www.domain.com/schema/data" xmlns:dmd="http://www.domain.com/schema/data-metadata" > <Something>...</Something> </Data> I am parsing the information using SimpleXML in PHP. I am dealing with arrays and I seem to be having a problem with the names...

PHP get XML attribute

Hi, Sorry if this seems like an easy question, but I've started pulling hair out on this... I have a XML file which looks like this... <VAR VarNum="90"> <option>1</option> </VAR> I'm trying to get the VarNum. So far I've been successful using the follow code to get the other information: $xml=simplexml_load_file($file); $option...

PHP: UTF 8 characters encoding

Hey I am scraping a list of RSS feeds by using cURL, and then I am reading and parsing the RSS data with SimpleXML. The sorted data is then inserted into a mySQL database. However, as notice on http://dansays.co.uk/research/MNA/rss.php I am having several issues with characters not displaying correctly. Examples: ‘Guitar Hero: Van ...

escape simpleXML errors

&lt;!-- MEMCACHE empty --&gt; The above is now causing issues for a script as it is now placed at the top of the XML files I'm trying to remotely access. simpleXML doesn't like the fact the XML file is no longer well formed. I tried escaping the errors but that didn't seem the do the trick. Can anyone point me in the direction on how ...

How to access element like <game:title> with simplexml?

Hello! I'm trying to parse XML feed with SimpleXML, here is a chunk of the XML tree: <item> <game:name>Tetris</game:name> <game:desc>Way Cool Game</game:desc> <size>5mb</size> </item> Well actually, I can succesfully access 'size' with something like that: $item->size, but how do I get value? Of course I can't call like that: $ite...

Parsing google calendar XML feed

Hi I've got XML feed from public google calendar. Looks like this: <?xml version='1.0' encoding='UTF-8'?> <feed xmlns='................' xmlns:gd='http://schemas.google.com/g/2005'&gt; <id>http://www.google.com/calendar/feeds/........./public/full&lt;/id&gt; <updated>2009-08-24T10:57:00.000Z</updated> <category schem...

Sort XML via attribute value PHP

So I have an XML file that I am trying to loop through in order, according to the attribute, "order". Here is an example: <page> <talentTrees> <tree name="Football" order="2"> <tree name="Baseball" order="0"> <tree name="Frisbee" order="1"> </talentTrees> </page> My goal is to loop through each "tree" using foreach, but I want to rea...

PHP Simplexml failing on localhost

Hi. I'm editing a mashup of mine where I fetch last.fm data through their API (xml). For some reason, my localhost can't connect to the file: it gives the following error. failed to open stream: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection ...

How to convert array to SimpleXML in PHP

I was wondering if anyone knew how to convert an array to a Simplexml object in PHP. Thanks ...

Multiple values in one attribute (such as class) in simplexml (using PHP)

If I try to add the same attribute twice to an element via simplexml, I get the following error: Warning: SimpleXMLElement::addAttribute() [function.SimpleXMLElement-addAttribute]: Attribute already exists... As a workaround, I'm using if-else statements for the three possibilities: if ($a && $b) { $node -> addAttribute("class", ...

Problem with simpleXML and entity not being defined

I'm trying to parse a XML file, but when loading it simpleXML prints the following warning: Warning: simplexml_load_file() [function.simplexml-load-file]: gpr_545.xml:55: parser error : Entity 'Oslash' not defined in import.php on line 35 This is that line: <forenames>B&Oslash;IE</forenames><x> </x> As it is a warning, I might ignor...