Thursday, February 7, 2013. DOM via PHP



Similar documents
Brazil + JDBC Juin 2001, douin@cnam.fr

Personnalisez votre intérieur avec les revêtements imprimés ALYOS design

Introduction au BIM. ESEB Seyssinet-Pariset Economie de la construction contact@eseb.fr

CSS : petits compléments

TP JSP : déployer chaque TP sous forme d'archive war

Note concernant votre accord de souscription au service «Trusted Certificate Service» (TCS)

Remote Method Invocation

Archived Content. Contenu archivé

Working with forms in PHP

Calcul parallèle avec R

Introduction Les failles les plus courantes Les injections SQL. Failles Web. Maxime Arthaud. net7. Jeudi 03 avril 2014.

«Object-Oriented Multi-Methods in Cecil» Craig Chambers (Cours IFT6310, H08)

Archived Content. Contenu archivé

Liste d'adresses URL

Langages Orientés Objet Java

POB-JAVA Documentation

Archived Content. Contenu archivé

Audit de sécurité avec Backtrack 5

Archived Content. Contenu archivé

Archived Content. Contenu archivé

PHP Tutorial From beginner to master

Archived Content. Contenu archivé

System Requirements Orion

Measuring Policing Complexity: A Research Based Agenda

Introduction. GEAL Bibliothèque Java pour écrire des algorithmes évolutionnaires. Objectifs. Simplicité Evolution et coévolution Parallélisme

Solaris 10 Documentation README

The wolf who wanted to change his color Week 1. Day 0. Day 1. Day 2. Day 3. - Lecture de l album

"Internationalization vs. Localization: The Translation of Videogame Advertising"

Modifier le texte d'un élément d'un feuillet, en le spécifiant par son numéro d'index:

Sun Management Center Change Manager Release Notes

niveau : 1 ere année spécialité : mécatronique & froid et climatisation AU : Programmation C Travaux pratiques

ETL Systems; XML Processing in PHP

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";! SET time_zone = "+00:00";!

Cours de Java. Sciences-U Lyon. Java - Introduction Java - Fondamentaux Java Avancé.

Archived Content. Contenu archivé

Documentation technique

CASifier une application

Survey on use of Taser International 21ft cartridges

SunFDDI 6.0 on the Sun Enterprise Server

Page intentionally left blank

Méthodes ensemblistes pour une localisation robuste de robots sous-marins

Veritas Storage Foundation 5.0 Software for SPARC

2 RENSEIGNEMENTS CONCERNANT L ASSURÉ SI CELUI-CI N EST PAS LE REQUÉRANT INFORMATION CONCERNING THE INSURED PERSON IF OTHER THAN THE APPLICANT

Archived Content. Contenu archivé

Introduction ToIP/Asterisk Quelques applications Trixbox/FOP Autres distributions Conclusion. Asterisk et la ToIP. Projet tuteuré

TP N 10 : Gestion des fichiers Langage JAVA

TP1 : Correction. Rappels : Stream, Thread et Socket TCP

In-Home Caregivers Teleconference with Canadian Bar Association September 17, 2015

Web - Travaux Pratiques 1

Web Programming with PHP 5. The right tool for the right job.

Sun Cluster 2.2 7/00 Data Services Update: Apache Web Server

Tanenbaum, Computer Networks (extraits) Adaptation par J.Bétréma. DNS The Domain Name System

TP : Configuration de routeurs CISCO

Installation. Installation centreon + nagios mai LISTE DES PRE-REQUIS. Nagios/centreon Paquets divers. 1.1.

HEALTH CARE DIRECTIVES ACT

Sun StorEdge A5000 Installation Guide


Bibliothèque numérique de l enssib

N1 Grid Service Provisioning System 5.0 User s Guide for the Linux Plug-In

Galaxy4Bioinformatics Développement et intégration d application sous Galaxy TOOL INTEGRATION

Internet Technologies

TP : Système de messagerie - Fichiers properties - PrepareStatement

VIREMENTS BANCAIRES INTERNATIONAUX

c. Write a JavaScript statement to print out as an alert box the value of the third Radio button (whether or not selected) in the second form.

site et appel d'offres

Multimedia im Netz Online Multimedia Winter semester 2015/16. Tutorial 03 Major Subject

Bibliothèque numérique de l enssib

The Register of the Domain of the State A Revolution in the Registration of Land Rights

RAPPORT FINANCIER ANNUEL PORTANT SUR LES COMPTES 2014

CS412 Interactive Lab Creating a Simple Web Form

Memo bconsole. Memo bconsole

Script Handbook for Interactive Scientific Website Building

Sun Enterprise Optional Power Sequencer Installation Guide

Sun Management Center 3.5 Update 1b Release Notes

Unrealized Gains in Stocks from the Viewpoint of Investment Risk Management

<?php if (Login::isLogged(Login::$_login_front)) { Helper::redirect(Login::$_dashboard_front); }

REQUEST FORM FORMULAIRE DE REQUÊTE

Tissot Pierre-Henri Recommended sites. Presentations : Online Activities

Développement Web 2. Node.js Installation de modules

A Document Visualization Tool Customized to Explore DRDC Reports. Peter Kwantes

REQUEST FORM FORMULAIRE DE REQUÊTE

at à 02 :00 PM on le

Short Form Description / Sommaire: Carrying on a prescribed activity without or contrary to a licence

Archived Content. Contenu archivé

Workshop. Avril 2015 Benoit Buonassera

La platforme RIM au dela de l Comment developper, integrer et deployer des applications

ACP-EU Cooperation Programme in Science and Technology (S&T II) / Programme de Coopération ACP-UE pour la Science et la Technologie

Interfaces de programmation pour les composants de la solution LiveCycle ES (juillet 2008)

Sun StorEdge RAID Manager Release Notes

"Templating as a Strategy for Translating Official Documents from Spanish to English"

WINDOWS SERVEUR 2003 EN CONCENTRE

Solaris 9 9/05 Installation Roadmap

Upgrading the Solaris PC NetLink Software

Active Offer of Service in both Official Languages

Website Report: To-Do Tasks: 22 SEO SCORE: 73 / 100. Add the exact keywords to this URL.

Transcription:

DOM via PHP

Plan PHP DOM

PHP : Hypertext Preprocessor Langage de script pour création de pages Web dynamiques Un ficher PHP est un ficher HTML avec du code PHP <html> <body> <?php echo "Hello World";?> </body> </html> Serveur Web <html> <body> Hello World </body> </html> PHP 5.0 orienté objet, vaste documentation sur php.net La suite du cours fera une introduction via exemples des éléments de base.

$i = 1; if (1 == $i) { echo "i est 1 <br>"; } else { echo "i n est pas 1<br>"; }; PHP, éléments de base switch ($i) { case 1: case 2: case 3: echo "i est soit 1 soit 2 soit 3 <br>"; break; case 4: echo "i est 4 "; break; default: echo "0 > i > 4"; }; while ($i < 4) { echo "i est $i<br>"; $i += 1; }; do { echo "i is $i"; $i--; } while ($i > 0); echo (0==$i? "i est a nouveu 0" : "i n est pas 0"); Sortie i est 1<br> i est soit 1 soit 2 soit 3<br> i est 1<br> i est 2<br> i est 3<br> i est 4<br> i est 3<br> i est 2<br> i est 1<br> i est a nouveu 0

PHP, formulaires <form action="action.php" method="post"> <p>votre nom : <input type="text" name="nom" /></p> <p>votre âge : <input type="text" name="age" /></p> <p><input type="submit" value="ok"></p> </form> Code dans action.php Bonjour, <? php echo htmlspecialchars($_post['nom']);?>. Tu as <?php echo (int)$_post['age'];?> ans. Les parameters peuvent etre passés en modalité GET aussi (attention, les valeurs sont concatenées à l URL de l action et sont transmises en claire)

DOM Document Object Model Un ensemble de librairies permettant le chargement d un document XML en mémoire primaire sous forme d arbre DOM permet de naviguer dans l arbre, et d effectuer des mises à jour DOM permet d'écrire sur disque le contenu de l arbre XML dans la mémoire primaire. DOM permet d'évaluer une requête XPath ou une transformation XSLT sur un document XML

Exemple, en image <books> <book> <author>jack Herrington</author> <title>php Hacks</title> <publisher>o'reilly</publisher> </book> <book> <author>jack Herrington</author> <title>podcasting Hacks</title> <publisher>o'reilly</publisher> </book> </books>

Lecture de document, et sélection d'éléments <?php $doc = new DOMDocument(); $doc->load( 'books.xml' ); $books = $doc->getelementsbytagname( "book" ); foreach( $books as $book ) { $authors = $book->getelementsbytagname( "author" ); $author = $authors->item(0)->nodevalue; $publishers = $book->getelementsbytagname( "publisher" ); $publisher = $publishers->item(0)->nodevalue; $titles = $book->getelementsbytagname( "title" ); $title = $titles->item(0)->nodevalue;?> } echo "$title - $author - $publisher\n";

Création de document et écriture <?php $books = array(); $books [] = array( 'title' => 'PHP Hacks', 'author' => 'Jack Herrington', 'publisher' => "O'Reilly" ); $books [] = array( 'title' => 'Podcasting Hacks', 'author' => 'Jack Herrington', 'publisher' => "O'Reilly" ); $doc = new DOMDocument(); $doc->formatoutput = true; $r = $doc->createelement( "books" ); $doc->appendchild( $r );...

Création de document et écriture... foreach( $books as $book ) { $b = $doc->createelement( "book" ); $author = $doc->createelement( "author" ); $author->appendchild( $doc->createtextnode( $book['author'] ) ); $b->appendchild( $author ); $title = $doc->createelement( "title" ); $title->appendchild( $doc->createtextnode( $book['title'] ) ); $b->appendchild( $title );...

Création de document et écriture... $publisher = $doc->createelement( "publisher" ); $publisher->appendchild( $doc->createtextnode( $book['publisher'] ) ); $b->appendchild( $publisher ); $r->appendchild( $b ); } echo $doc->savexml();?>

Evaluation de requêtes XPath Exemple : compter le nombre de livres écrits par un auteur Version sans XPath <?php $doc = new DOMDocument; $doc->load('book.xml'); $author = nom auteur ; $total = 0; $elements = $doc->domdocument->getelementsbytagname("author"); foreach ($elements as $element) { if ($element->nodevalue == $author) { $total++; }}...

Evaluation de requetes XPath Exemple : compter le nombre de livres écrits par un auteur Version 1 avec XPath <?php $author = nom auteur ; $doc = new DOMDocument; $doc->load('book.xml'); $xpath = new DOMXPath($doc); $query = "//book[author= $author ]"; $result = $xpath->query($query);...

Evaluation de requêtes XPath Exemple : compter le nombre de livres écrits par un auteur Version 2 avec XPath <? $doc = new DOMDocument; $doc->load('book.xml'); $xpath = new DOMXPath($doc); $query = "count(//book[author= $author ])"; return $xpath->evaluate($query);...?>

XSLT via PHP $xp = new XSLTProcessor(); $xsl = new DOMDocument; $xsl->load('unetransformationxmltohtml.xsl'); $xp->importstylesheet($xsl); $xmldoc = new DOMDocument; $xmldoc->load('document.xml'); $html = $xp->transformtoxml($xmldoc); echo $html;

Exercice Ecrire une page Web pour la recherche des livres par auteur, et pour l insertion de livres, dans le fichier books.xml