knightly

Monthly Archives: October 2008

Parsing XML CDATA with SimpleXML

I was quite amazed today. When loading a SOAP response into a SimpleXMLElement i noticed some fields were left blank. I should have checked the SOAP response first. But instead told our Delphi guy that the response was not filled correctly. This was not the case :)

When we both saw the SOAP response was in perfect shape. We started to poke around on the PHP side. The strange thing was all tag names were taken from the response correctly. It was just the data that was missing. Then we noticed the data missing was inside CDATA tags.

From a first glance at the PHP manual it it wasn’t clear what was going on. So i did some googleing. And found a good post by David Coallier. This post solved the problem. The example showed how to add an extra LIBXML options to the simplexml_load_String method. Although David provided the solution. I still wanted to make post. Maybe it will help somebody.

    // parsing with CDATA tags using the *_load_string method
    $xml = simplexml_load_string($string, 'SimpleXMLElement', LIBXML_NOCDATA);

    // parsing with CDATA tags using the OO way
    $xml = new SimpleXMLElement($string, LIBXML_NOCDATA);

The LIBXML options that can be passed to the *_load methods and constructor can be found in the php documentation.

It’s pretty damn weird though. I want to parse the CDATA tags inside my XML. And can only do so by providing the NOCDATA option.

Load MOOdalBoxes without clicking links

The MOOdalBox script is a great addition to the mootools library. The interface is pretty slick. And easy to style with just CSS. Răzvan Brateş did a great job here. And every now and then i have to implement one of those MOOdalBoxes in a web application. No problem here.

Until today all MOOdalBoxes i used were triggered by simply clicking a link on a page. But today i needed to load a MOOdalBox window on page load. The screen represented some sort of QuickStart menu. Which can be disabled. I had no idea how to trigger the MOOdalBox from javascript. But once i read through the source. It became clear that it should be as easy as calling:

MOOdalBox.open(url, title, sizes);

This kept giving me the following error:

this.overlay is undefined

Looking through the MOOdalBox source. I noticed the this.overlay property was set inside the init() method. So let’s try that before we call the open() method.

MOOdalBox.init();
MOOdalBox.open(url, title, sizes);

This actually worked. I was pretty happy with the result. untill i opened IE 7 to test the same page. Nothing happened. No error’s and no MOOdalBox. Let’s try something else. Whenever i need to load something on page load in IE i use the window.onload method.

window.onload = function()
    MOOdalBox.init();
    MOOdalBox.open(url, title, sizes);
}

Now the overlay was loaded. But still no MOOdalBox on top of it. I figured it had something to do with the DOM not being fully loaded. But i couldn’t really think of a solution. So of to Google. After a bit of browsing i found somebody with the same problem. And a reply from the original author of MOOdalBox. Add a domready event to make it work.

window.addEvent('domready', loadMOOdal);
function loadMOOdal() {
    MOOdalBox.open('Quickstart/load', '', '700 500');
}

This did it. And my only goal was to make it function properly inside of IE 7. but this also fixes the same problem for IE 6. So a big thanks to Răzvan for creating MOOdalBox and for supplying the fix.

ATP is seeking web developers

For the past three years I’ve been working as a web developer for ATP in the Netherlands. This has been a great experience. And still is. I have the pleasure of working with some really smart people here. Who are always eager to work with the newest technologies. This offers a great learning ground for all of us. The projects have evolved over the years. From simple websites to complex web applications.

Right now we are looking for some experienced web developers to strengthen the team. we are looking for somebody who master the following skills.

  • PHP Specialist (a minimum of 3 years experience)
  • Object oriented experience
  • Good knowledge of XML, SQL, JavaScript en CSS
  • Experienced with web services (SOAP, XML-RPC)
  • You are flexible, pro-active, pragmatic and eager to learn
  • You can work alone or in a team
  • You have good communicative skills in Dutch and English
  • You are able to prioritize in hectic situations

We offer a great working environment. Good secondary working conditions. A year contract with the intention to prolong.

If you are located in the Schiphol / Amsterdam area. And are looking for a good job. take your chance. For more information take a look at atp.nl. If you are interested drop me a line.

Stop ACTA