simplexml

PHP SimpleXML select attributes

I have an XML feed that looks like this: <?xml version="1.0" encoding="UTF-8"?> <productFeed version="1.0" timestamp="20100910:04:06:55"> <product id="196"> <name>Lorem</name> <price>190.00</price> <description>Lorem Ipsum</description> <productURL> http://www.example.com&lt;/productURL&gt; <imageURL> http://www.exam...

xPath finds nothing but *

This is starting to piss me off real bad. I have this XML code: Updated with correct namespaces <?xml version="1.0" encoding="utf-8"?> <Infringement xsi:schemaLocation="http://www.movielabs.com/ACNS http://www.movielabs.com/ACNS/ACNS2v1.xsd" xmlns="http://www.movielabs.com/ACNS" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&g...

How do I get my values out of their SimpleXMLObjects ?

After an xPath, I'm left with this var_dump: array(1) { [0]=> object(SimpleXMLElement)#2 (1) { [0]=> string(11) "22-99586795" } } echoing the damn thing only gives me "Array()" How do I get the bloody string out? Thanks ...

Atom namespace with php simplexml

This is my RSS template that I load into my simplexml object. I want to change the <?xml version="1.0" encoding="utf-8"?> <rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"> <channel> <atom:link href="link" rel="self" type="application/rss+xml" /> <title></title> <link></link> <description><...

Accessing a XML node directly via a key

$xml = simplexml_load_file($xmlPath); $items = $xml->list->item; ... echo $items[$currentIndex]->asXML(); When I print out $currentIndex on each iteration, I get 0, 1, 2, 3, 4, etc. When I hard code $items[0]->asXML(); $items[1]->asXML(); $items[2]->asXML(); etc. I get the data I want. But when I loop like I do in the first code segme...

Does extra space slow down the processor?

After learning how to "correctly" unset a node, I noticed that using PHP's unset() function leaves the tabs and spaces behind. So now I have this big chunk of white space in between nodes at times. I'm wondering if PHP iterates through blank spaces/returns/tabs and whether it would eventually slow down the system. I'm also asking whethe...

Problem with dom_import_simplexml on newly created SimpleXML nodes

I'm working on a class extending SimpleXMLElement: class MyXML extends SimpleXMLElement { public function cdata($text) { $node = dom_import_simplexml($this); $owner = $node->ownerDocument; $node->appendChild($owner->createCDATASection($text)); return $this; } } Since it's an SimpleXMLElement, I ...

Use XPath with PHP's SimpleXML to find nodes containing a String

Hi! I try to use SimpleXML in combination with XPath to find nodes which contain a certain string. <?php $xhtml = <<<EOC <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt; <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de" lang="de"> <head> <meta http-e...

Succinct version of simplexml/xpath?

Currently I have: $content = ($propXml->xpath('//content/section[@name="accommodations"]/content')); $content = is_array($content) && (count($content)>0)?(string)$content[0]:false; echo $content; Is there a more succinct way of doing this? It would be shorter if PHP had the ability to automatically access an assigned array, but I hav...

cannot find custom namespace in xml

Hi all, Could someone please help me out with this. I need to find the gml:pos namespace in the xml. But, very important! - in the $item part off the loop I really have no clue how to get this done. The namespace is in another custom namespace according to google-api docs. $feed = simplexml_load_string($feedXml); foreach ($feed->en...

Is there anyway to make simpleXML work on web host.

<?php $twitter_url = 'http://twitter.com/statuses/user_timeline/ishrikrishna.xml?count=1'; $buffer = file_get_contents($twitter_url); $xml = new SimpleXMLElement($buffer); $status = $xml -> status; $tweet = $status -> text; echo $tweet; ?> I used this code to fetch tweets and it works successfully on localhost but not on my ...

PHP's SimpleXML doesn't save edited data

I'm trying to edit some xml data. After this I want to save the data to file. The problem is that the edited data isn't saved by simplexml but the node has changed. $spieler = $xml->xpath("/planer/spieltag[@datum='" .$_GET['date']. "']/spielerliste/spieler"); for ( $i = 1; $i < 13; $i++ ){ if (!empty($_POST['spieler' .$i ])){ ...

array variable index in that rare SimpleXML functions

hi very good, I have a label on a form select and I get that value with $ _POST like this: $gallery = array($_POST['gallery']); and that value will put it here: $image = $sitemap->gallery[$gallery]->addChild('image'); the problem is giving me error is as follows: Fatal error: Call to a member function addChild() on a non-object in...

How to parse an eXist xQuery response with php?

Hi, I am trying to find an easy way to parse an eXist response with php without installing third party classes. This is the type of response that I would like to parse : <exist:result xmlns:exist="http://exist.sourceforge.net/NS/exist"&gt; <exist:collection name="xData" path="/db/SBXXX/00000000-00000000/sapData" created="2010-07-15T...

How to add an attribute to an HTML string using DOM/SimpleXML

I want to alter the class attribute of an image tag in PHP. I could do it using regex but want to use DOM / SimpleXML. The simplexml element looks like this: $obj = simplexml_load_string($unprocessedfield); var_dump($obj->img); object(SimpleXMLElement)#108 (1) { ["@attributes"]=> array(6) { ["class"]=> string(33) "alig...

Is there something similar in ASP.NET to PHP's SimpleXML

If I want to convert my PHP application to ASP.NET… what do you recommend and why? I'm currently using PHP's simplexml_load_string() method because it's, well, …simple. For example, for PHP to process an http request in the form of XML I just use: $FILERAWDATA = file_get_contents("php://input"); $xml = simplexml_load_string($FILERAW...

SimpleXML::addChild() can't add line break when output to a xml

<?xml version="1.0" encoding="utf-8"?><items> <item><title>title3</title><desc>This is some desc3</desc></item></items> There is no line break between each node element when using asXML() to output? how to make output the file well-structured by adding link break <?xml version="1.0" encoding="utf-8"?> <items> <item> <title>title3</ti...

XML parser error: entity not defined

I have searched stackoverflow on this problem and did find a few topics, but I feel like there isn't really a solid answer for me on this. I have a form that users submit and the field's value is stored in a XML file. The XML is set to be encoded with UTF-8. Every now and then a user will copy/paste text from somewhere and that's when ...

simpleXML returns empty element

I got a problem reading an XML-Feed Sample of the XML File: <f:feed xmlns:f="http://www.bbgo.de/feedxml/feed" xmlns:a="http://www.bbgo.de/feedxml/article" xmlns="http://www.w3.org/1999/xhtml" f:customer="blub" f:name="dax-tecdax"> <f:title>Analysen: DAX, TecDAX</f:title> <f:date>2010-09-22T20:46:29+02:00</f:date> <f:url>http://www.bbgo....

PHP, SimpleXML arrays. Unanticipated casting of an array to a string

Sample XML: <root> <ratings>3</ratings> <ratings>5</ratings> <ratings>7</ratings> </root> The following code is the basis for my small application, it works as would be expected: <?php // $xml is some simplexml object sizeof($xml->ratings); //3 foreach($xml->ratings as $rating){ echo($rating->value."::"); //thi...