simplexml

PHP simplexml problem

I have the following XML structure: <?xml version="1.0" ?> <course xml:lang="nl"> <body> <item id="787900813228567" view="12000" title="0x|Beschrijving" engtitle="0x|Description"><![CDATA[Dit college leert studenten hoe ze een onderzoek kunn$ <item id="5453116633894965" view="12000" title="0x|Onderwijsvorm" engtitle="0x|Method...

Using SimpleXML to create an XML object from scratch

Is it possible to use PHP's SimpleXML functions to create an XML object from scratch? Looking through the function list, there's ways to import an existing XML string into an object that you can then manipulate, but if I just want to generate an XML object programmatically from scratch, what's the best way to do that? I figured out tha...

What puts less load on a PHP server: SimpleXML or json_decode?

I'm starting to develop a web application in PHP that I hope will become incredibly popular and make me famous and rich. :-) If that time comes, my decision whether to parse the API's data as XML with SimpleXML or to use json_decode could make a difference in the app's scalability. Does anyone know which of these approaches is more eff...

PHP SimpleXML::addChild with empty string - redundant node

Calling addChild with an empty string as the value (or even with whitespace) seems to cause a redundant SimpleXml node to be added inside the node instead of adding just the node with no value. Does anyone know of a workaround for this? ...

Turn OFF self-closing tags in SimpleXML for PHP?

I'm building an XML document with PHP's SimpleXML extension, and I'm adding a token to the file: $doc->addChild('myToken'); This generates (what I know as) a self-closing or single tag: <myToken/> However, the aging web-service I'm communicating with is tripping all over self-closing tags, so I need to have a separate opening and c...

PHP SimpleXML, CodeIgniter and Apache with Suhosin

I have an application I am writing in PHP5, using the CodeIgniter framework. I have it running on both Windows (using Xampp) and Ubuntu (using standard Apache, PHP, MySQL stack). I have a form, that takes XML, parses it (using simpleXML) and posts the results into a database. On Windows - no problem, works as intended. On Linux - big ...

Remove a child with a specific attribute, in SimpleXML for PHP

I have several identical elements with different attributes that I'm accessing with SimpleXML: <data> <seg id="A1"/> <seg id="A5"/> <seg id="A12"/> <seg id="A29"/> <seg id="A30"/> </data> I need to remove a specific seg element, with an id of "A12", how can I do this? I've tried looping through the seg elements an...

PHP SimpleXML. How to get the last item?

How would I get the last item (or any specific item for that matter) in a simplexml object? Assume you don't know how many nodes there will be. ex. <?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet type="text/xsl" href="/xsl.xml"?> <obj href="http://xml.foo.com/" display="com.foo.bar" xmlns:xsi="http://www.w3.org/2001/XM...

Why is this regex returning errors when I use it to fish img src's from HTML?

I'm writing a function that fishes out the src from the first image tag it finds in an html file. Following the instructions in this thread on here, I got something that seemed to be working: preg_match_all('#<img[^>]*>#i', $content, $match); foreach ($match as $value) { $img = $value[0]; } $stuff = s...

Something similar to PHP's SimpleXML in Python?

Is there a way in Python to handle XML files similar to the way PHP's SimpleXML extension does them? Ideally I just want to be able to access certain xml datas from a list object. ...

Call to a member function xpath() on a non-object?

I'm trying to grab an image from a web site using simpleXML and am getting a PHP error saying that I'm trying to call to a member function xpath() on a non-object. Below are the lines I'm trying to use to get the image's source tag: $xpath = '/html/body/div/div/div[5]/div/div/div[2]/div/div[2]/img'; $html = new DOMDocument()...

PHP simplexml: why does xpath stop working?

A strange thing happened after a supplier changed the XML header a bit. I used to be able to read stuff using xpath, but now I can't even get a reply with $xml->xpath('/'); They changed it from this... <?xml version="1.0" encoding="iso-8859-1"?> <!DOCTYPE NewsML SYSTEM "http://www.newsml.org/dl.php?fn=NewsML/1.2/specification/NewsML_...

Add, update and edit an XML file with PHP

I have an xml file which I would like to create a form/table around to add, edit and delete records using PHP. Currently I use simpleXML to load the XML file, and display its content on various pages. Is there any way I can create a table that shows all results, and allows me to either edit or delete that particular row of the table wh...

Scraping using PHP + SimpleXML... I can grab images but not raw text?

I'm trying to grab a specific bit of raw text from a web site. Using this site and other sources, I learned how to grab specific images using simpleXML and xpath. However the same approach doesn't appear to be working for grabbing raw text. Here's what's NOT working right now. // first I set the xpath of the div that contains the text...

Forcing a SimpleXML Object to a string, regardless of context

Let's say I have some XML like this <channel> <item> <title>This is title 1</title> </item> </channel> The code below does what I want in that it outputs the title as a string $xml = simplexml_load_string($xmlstring); echo $xml->channel->item->title; Here's my problem. The code below doesn't treat the title as a string in ...

Transforming Point object when using simple-xml

I am serializing a class using simple-xml (http://simple.sourceforge.net/) but when i try to use @Element on a Point object i get an error, how can i transform this Point object? ...

Unknown exception while deserializing using simple XML

I am deserializing data using Simple XML in Java, but i get an exception telling me: protokolsimulering.model.Terminal.<init>() This is my serializing code: public void saveSimulationState(String simulationFile) { try{ Strategy strategy = new CycleStrategy("id", "ref"); Serializer serializer = new Persister(strate...

PHP XML Parsing

Which is the best way to parse an XML file in PHP ? First Using the DOM object //code $dom = new DOMDocument(); $dom->load("xml.xml"); $root = $dom->getElementsByTagName("tag"); foreach($root as $tag) { $subChild = $root->getElementsByTagName("child"); // extract values and loop again if needed } Second Using the simplexml_load Me...

Is there any way to retreive the comments from an XML file?

Is there any way to retrieve the comments from an XML file? I have an XML file, with comments in it, and i have to build an user-interface based on each node in this file, and the associated comments. I can't seem to find a way to get those comments. I was able to get 'some' of them using simpleXML, but it didn't work for the root node...

Recursively find all the nodes from an XML having a given argument with PHP / simpleXML

Hi guys, Like I said in the title, I was wondering whether it would be possible and how, to recursively parse an XML document and return all the nodes that have a given argument. What I'm actually trying to do is to load and XHTML document and return all the nodes (P nodes, DIV nodes, etc.) that have a class equal to a previously defin...