background preloader

DOM, XML, JSON

Facebook Twitter

Gestion du XML en PHP 5 : utiliser DOM, par Guillaume Piolle - C. Ce tutoriel suppose que vous connaissez (au moins basiquement) XML.

Gestion du XML en PHP 5 : utiliser DOM, par Guillaume Piolle - C

Les exemples de documents XML utilisés dans ce document ne doivent pas être considérés comme des modèles de structuration de données... Ils ont été choisis pour illustrer des problématiques précises relatives à l'API DOM. Nous allons travailler sur un document XML constitué d'une liste de quelques pays, classés par continents. Les informations contenues dans ce tutoriel concernent la version 5.0.0 de PHP.

Dans cette version, les fonctions DOM XML ne lancent pas d'exception DomException en cas d'erreur. Ce tutoriel a vocation à évoluer, et vous êtes vivement invités à participer en contactant l'auteur pour signifier les erreurs que vous y aurez trouvées, les nouvelles sections que vous aimeriez y voir, et de manière générale toutes les modifications qui pourraient y être apportées. A la différence de l'extension de PHP4 qui était assez procédurale, l'extension DOM de PHP5 est entièrement objet. 2.1. Sélectionnez <? <? 2.2.

<? DOMDocument. DOMNode. You cannot simply overwrite $textContent, to replace the text content of a DOMNode, as the missing readonly flag suggests.

DOMNode

Instead you have to do something like this: <? Php $node->removeChild($node->firstChild);$node->appendChild(new DOMText('new text content')); ? $doc = DOMDocument::loadXML('<node>old content</node>');$node = $doc->getElementsByTagName('node')->item(0); echo "Content 1: ". $node->textContent = 'new content'; echo "Content 2: ". $newText = new DOMText('new content'); $node->appendChild($newText); echo "Content 3: ". $node->removeChild($node->firstChild);$node->appendChild($newText); echo "Content 4: ". ? Content 1: old content // starting content Content 2: old content // trying to replace overwriting $node->textContent Content 3: old contentnew content // simply appending the new text node Content 4: new content // removing firstchild before appending the new text node If you want to have a CDATA section, use this:

DOMNodeList. JavaScript in Chrome. Google Chrome has taken the browser world by storm.

JavaScript in Chrome

It makes for an exciting release, no doubt, especially with a brand new JavaScript engine on the table. However the most important question, to JavaScript developers, is: How will this affect my normal development routine? I’ve done some research, talked to some developers, submitted some bugs and come back with a list of things that you should probably be aware. In all, there are some exciting tweaks, simple bugs, and baffling removals.

Timer Delay Absolutely the most exciting change: Timer delays are the value that you set. SetTimeout(someFunction, 2); then someFunction will attempt to execute in 2 milliseconds (depending on if there’s any other extenuating circumstances, naturally). The only exception to the above is if a timer delay of < 1ms is provided then it will be rounded up to 1ms. I’ve done some analysis on this in the past and found that all browsers bottom-out at a certain point. No Script Execution Dialog for loop order. Référence du DOM Gecko - MDC.