simplexml

PHP: Using simplexml to loop through all levels of an XML file

I have a function which uses simplexml to return the first level of nodes in an XML file and write it into an unordered list: function printAssetMap() { $xml = simplexml_load_file(X_ASSETS); $assets = $xml->asset; $html = '<ul>'."\n"; foreach ($assets as $asset) { $html .= '<li id="asset'.$asset->asset_assetid.'"...

Using simplexml to get a node (and its children) by attribute

Using simplexml, is it possible to get the children of a node based on the parent's attributes. For example, I want to get a list of the variants in myItem1 (output would be small, large) Here is some psuedo code of what I'm after: foreach($xml->xpath('//family[@name="myItem1"]')->variants->children() as $child) { $child->getName()...

Choosing Last Node in SimpleXML

Hi , I want to find the attribute of the last node in the xml file. the following code find's the attribute of the first node. Is there a way to find the last node ? foreach ($xml->gig[0]->attributes() as $Id){ } thanks ...

How do I load the contents of an rss feed rendered by php?

Wordpress is rendering an RSS feed at http://myurl.com/feed/rss/ but of course there's not actually a file there. I'm writing a script to read and render the RSS, but loading the "file" as XML fails, because there's not actually a file there. I write: $rss = simplexml_load_file('/news/feed/rss/'); And I get this error: Warning: simp...

SimpleXML node attribute loop

Hi , I am having a little problem how can I turn the following code into a whileloop , I know how to create a whileloop but working with the simpleXML code seems to throw me of course. my code get me either the first or last attribute but I need all of them. can any one help <?php foreach (current($xml->xpath('/*/gig[last()]'))->a...

Is it possible to insert a comment tag into an xml using simplexml?

I am using SimpleXML to build a document, and wondering whether it is possible to insert comment tag to the document like this: <root> <!-- some comment --> <value> </root> EDIT: The comment is somewhere in the middle of the document. <root> <tag1 /> <!-- some comment --> <value /> </root> ...

How to loop and display (n) feeds using simpleXML and position()

Hi, I am using simpleXML and I want to loop though the feed to only display 5 shows using the position() method, but have no joy in getting it to work foreach($xml->sortedXPath('TV[position() < 5 and ProgrammeName="MTV"]', 'TransmissionDate', SORT_DESC) as $i => $item) { print "<a href='?v=".$item->ID."&a=false' class='link'>\n"; ...

php5 simple_xml_file parse error

Hello, I am trying to pass the XML code below, in the first instance using the php function simplexml_load_file. Currently the php code is incredibly simple as follows: if (file_exists('test.xml')) { $xml = simplexml_load_file('test.xml'); print_r($xml); } else { exit('Failed to open test.xml.'); } However on running th...

Firefox-only bug when calling .flv videos from xml file using php

I have a simple site put together to play a few flash videos. I have the information for the videos and their related comments stored in an xml file. I use SimpleXML to iterate through all of this and display the stuff in reverse chronological order. Everything works perfectly in IE8, Safari, and Chrome, but in Firefox the same video (t...

Access an element's parent with PHP's SimpleXML?

I'm iterating through a set of SimpleXML objects, and I can't figure out how to access each object's parent node. Here's what I want: $divs = simplexml->xpath("//div"); foreach ($divs as $div) { $parent_div = $div->get_parent_node(); // Sadly, there's no such function. } Seems like there must be a fairly easy way to do this. ...

Find if node has siblings using simplexml

I am try to find if a certain node has siblings, and if it does, I would like to know what those siblings are. Is this possible? ...

XPath result to PHP Object

Hi, I have an xml file which represents a number of objects for which I have a class in my application. For example, blogposts: <blogposts> <blogpost id="604"> <title>afdghadfh</title> <body>adfgadfgda</body> </blogpost> <blogpost id="605"> <title>dafghadh</title> <body>afadf</body> </blogpost> </blogposts> ...

XPath Query using contains with multiple values

I need an XPath that will elect all parent nodes a child with anattribute that constains at least one of a list of values. Example XML <mynodes> <theParentNode> <theChildNode name="one two" /> </theParentNode> <theParentNode> <theChildNode name="one all" /> </theParentNode> <theParentNode> <theChildNode name="...

how can i add the namespace name before the attribute in xml using simplexml

hi, how can i add namespace name before a attribute of newly created tag,like <Data ss:Type="String">this the value of data</Data> but can create only <Data Type="String">this the value of data</Data> so i can not add "ss:" before atttbute. Thanks in Advance Have Dream Day ...

Getting values from XML elements which has the same names using PHP

I have a problem in getting the values from all the 3 IMAGE elements coz they have the same name. Below is my xml feed <FOUND> <IMAGES> <IMAGE> <SMALL>images/small.jpg</SMALL> <MED>images/med.jpg</MED> <LARGE>images/large.jpg</LARGE> <EXTRAL>images/extra.jpg</EXTRAL> </IMAGE> <IMAGE> <SM...

PHP won't echo XML child

Here is my code <form method="post"> <input name="hash" type="text" id="hash" style='width: 30%;'/> <input name="Crack!" type="submit" value="Crack!" onfocus="if(this.blur)this.blur()"/> </form> <?php if(isset($_POST['Crack!'])){ $hash = $_POST['hash']; $xml = simplexml_load_file("http://gdataonline.com/q...

Scraping YouTube XML to embed via SimpleXML—where am I going wrong?

I'm trying to use this query to find the precise videos I want via XML, then I'm looking to parse the values with SimpleXML and insert them in the DOM via this method. I was experiencing a strange problem earlier when pulling the value from: <media:player url='http://www.youtube.com/watch?v=ikACkCpJ-js&amp;amp;feature=youtube_gdata'/&...

How would I echo this in PHP using SimpleXML

Response example for MD5 hash found, for example http://md5.noisette.ch/md5.php?hash=2a0231531bc1a7fc29e2fa8d64352ae9 : <md5lookup> <hash>2a0231531bc1a7fc29e2fa8d64352ae9</hash> <string>noisette</string> </md5lookup> Response for MD5 hash *not* found, for example http://md5.noisette.ch/md5.php?hash=11111111111111111111111111111111 ...

SimpleXML returning multiple objects, how can I get the data?

I'm using simpleXML to parse this xml file. It's a feed I'm using to access the YouTube API. I want to embed the most recent video in an object and display the next four thumbnails. So I'm using simplexml_load_file on this, going using a foreach loop to access the values in each feed. I can access the values no problem, but I run into ...

Adding node using PHP's SimpleXML to XML with namespaces.

<?xml version="1.0" encoding="ISO-8859-2"?> <!DOCTYPE pasaz:Envelope SYSTEM "loadOffers.dtd"> <pasaz:Envelope xmlns:pasaz="http://schemas.xmlsoap.org/soap/envelope/"&gt; <pasaz:Body> <loadOffers xmlns="urn:ExportB2B"> <offers /> </loadOffers> </pasaz:Body> </pasaz:Envelo...