<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Blog de Jonathan Petitcolas &#187; validation</title>
	<atom:link href="http://www.jonathan-petitcolas.com/tag/validation/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.jonathan-petitcolas.com</link>
	<description>Geek, développeur Web, passionné de high-tech</description>
	<lastBuildDate>Sat, 21 Aug 2010 14:47:30 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Valider un fichier XML avec un schéma de définition (XSD) en PHP</title>
		<link>http://www.jonathan-petitcolas.com/valider-un-fichier-xml-avec-un-schema-de-definition-xsd-en-php/</link>
		<comments>http://www.jonathan-petitcolas.com/valider-un-fichier-xml-avec-un-schema-de-definition-xsd-en-php/#comments</comments>
		<pubDate>Wed, 14 Jan 2009 11:08:28 +0000</pubDate>
		<dc:creator>Jonathan Petitcolas</dc:creator>
				<category><![CDATA[Développement]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[validation]]></category>
		<category><![CDATA[xml]]></category>
		<category><![CDATA[xsd]]></category>

		<guid isPermaLink="false">http://www.jonathan-petitcolas.com/?p=694</guid>
		<description><![CDATA[Je vous avais déjà parlé, il y a quelques mois, de la manière de <a href="http://www.jonathan-petitcolas.com/valider-un-document-xml-avec-un-xsd-sous-linux/">valider un XML avec un XSD sous Linux</a>, en utilisant la commande Linux <em>xmllint</em>. Eh bien, à présent, nous allons voir comment le valider sous toutes les plates-formes ayant un simple Apache de configuré (et intégrant PHP 5 bien sûr !).]]></description>
			<content:encoded><![CDATA[<p>Je vous avais déjà parlé, il y a quelques mois, de la manière de <a href="http://www.jonathan-petitcolas.com/valider-un-document-xml-avec-un-xsd-sous-linux/">valider un XML avec un XSD sous Linux</a>, en utilisant la commande Linux <em>xmllint</em>. Eh bien, à présent, nous allons voir comment le valider sous toutes les plates-formes ayant un simple Apache de configuré (et intégrant PHP 5 bien sûr !).</p>
<p>Pour ce faire, nous allons utiliser la classe <em>DOMDocument</em>, une classe PHP5 bien pratique permettant de manipuler les documents XML très simplement. Voici les quelques lignes de code correspondantes :</p>
<pre class="brush: php;">&amp;lt;?php

	$doc = new DOMDocument();

	$doc-&amp;gt;load($_GET['xml'].'.xml');
	$doc-&amp;gt;schemaValidate($_GET['xsd'].'.xsd');

	echo &amp;quot;&amp;lt;hr/&amp;gt;&amp;lt;pre&amp;gt;&amp;quot;.htmlentities($doc-&amp;gt;saveHTML()).&amp;quot;&amp;lt;/pre&amp;gt;&amp;quot;;

?&amp;gt;</pre>
<p>Et c'est tout. Quelques explications (superflues ?). On commence par instancier notre classe <em>DOMDocument</em> et on charge le fichier XML passé en URL. Puis, on le valide avec un fichier XSD passé lui aussi en URL. La méthode <em>schemaValidate</em> affichera des <em>warning</em> si le document n'est pas valide, et n'affichera rien si le document est valide. Bref, il s'agit d'un moyen très simple pour les Windowsiens de vérifier si un document XML est bien conforme à un schéma XML. </p>
<p>Enfin, petite cerise sur le gâteau : on affiche le fichier XML dans notre page. :)</p>


<div class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-center shr-bookmarks-bg-knowledge">
<ul class="socials">
		<li class="shr-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://www.jonathan-petitcolas.com/valider-un-fichier-xml-avec-un-schema-de-definition-xsd-en-php/&amp;t=Valider+un+fichier+XML+avec+un+sch%C3%A9ma+de+d%C3%A9finition+%28XSD%29+en+PHP" rel="nofollow" class="external" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="shr-twitter">
			<a href="http://twitter.com/home?status=Jonathan+Petitcolas+%3A+Valider+un+fichier+XML+avec+un+sch%C3%A9ma+de+d%C3%A9finition+%28XSD%29+en+PHP+-+http://tinyurl.com/ms52om&amp;source=shareaholic" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="shr-netvibes">
			<a href="http://www.netvibes.com/share?title=Valider+un+fichier+XML+avec+un+sch%C3%A9ma+de+d%C3%A9finition+%28XSD%29+en+PHP&amp;url=http://www.jonathan-petitcolas.com/valider-un-fichier-xml-avec-un-schema-de-definition-xsd-en-php/" rel="nofollow" class="external" title="Submit this to Netvibes">Submit this to Netvibes</a>
		</li>
		<li class="shr-linkedin">
			<a href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http://www.jonathan-petitcolas.com/valider-un-fichier-xml-avec-un-schema-de-definition-xsd-en-php/&amp;title=Valider+un+fichier+XML+avec+un+sch%C3%A9ma+de+d%C3%A9finition+%28XSD%29+en+PHP&amp;summary=Je%20vous%20avais%20d%C3%A9j%C3%A0%20parl%C3%A9%2C%20il%20y%20a%20quelques%20mois%2C%20de%20la%20mani%C3%A8re%20de%20valider%20un%20XML%20avec%20un%20XSD%20sous%20Linux%2C%20en%20utilisant%20la%20commande%20Linux%20xmllint.%20Eh%20bien%2C%20%C3%A0%20pr%C3%A9sent%2C%20nous%20allons%20voir%20comment%20le%20valider%20sous%20toutes%20les%20plates-formes%20ayant%20un%20simple%20Apache%20de%20configur%C3%A9%20%28et%20int%C3%A9grant%20PHP%205%20bien%20s%C3%BBr%20%21%29.&amp;source=Blog de Jonathan Petitcolas" rel="nofollow" class="external" title="Share this on LinkedIn">Share this on LinkedIn</a>
		</li>
		<li class="shr-googlebuzz">
			<a href="http://www.google.com/buzz/post?url=http://www.jonathan-petitcolas.com/valider-un-fichier-xml-avec-un-schema-de-definition-xsd-en-php/&amp;imageurl=" rel="nofollow" class="external" title="Post on Google Buzz">Post on Google Buzz</a>
		</li>
		<li class="shr-googlereader">
			<a href="http://www.google.com/reader/link?url=http://www.jonathan-petitcolas.com/valider-un-fichier-xml-avec-un-schema-de-definition-xsd-en-php/&amp;title=Valider+un+fichier+XML+avec+un+sch%C3%A9ma+de+d%C3%A9finition+%28XSD%29+en+PHP&amp;srcUrl=http://www.jonathan-petitcolas.com/valider-un-fichier-xml-avec-un-schema-de-definition-xsd-en-php/&amp;srcTitle=Valider+un+fichier+XML+avec+un+sch%C3%A9ma+de+d%C3%A9finition+%28XSD%29+en+PHP&amp;snippet=Je%20vous%20avais%20d%C3%A9j%C3%A0%20parl%C3%A9%2C%20il%20y%20a%20quelques%20mois%2C%20de%20la%20mani%C3%A8re%20de%20valider%20un%20XML%20avec%20un%20XSD%20sous%20Linux%2C%20en%20utilisant%20la%20commande%20Linux%20xmllint.%20Eh%20bien%2C%20%C3%A0%20pr%C3%A9sent%2C%20nous%20allons%20voir%20comment%20le%20valider%20sous%20toutes%20les%20plates-formes%20ayant%20un%20simple%20Apache%20de%20configur%C3%A9%20%28et%20int%C3%A9grant%20PHP%205%20bien%20s%C3%BBr%20%21%29." rel="nofollow" class="external" title="Add this to Google Reader">Add this to Google Reader</a>
		</li>
		<li class="shr-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://www.jonathan-petitcolas.com/valider-un-fichier-xml-avec-un-schema-de-definition-xsd-en-php/&amp;title=Valider+un+fichier+XML+avec+un+sch%C3%A9ma+de+d%C3%A9finition+%28XSD%29+en+PHP" rel="nofollow" class="external" title="Digg this!">Digg this!</a>
		</li>
		<li class="shr-delicious">
			<a href="http://delicious.com/post?url=http://www.jonathan-petitcolas.com/valider-un-fichier-xml-avec-un-schema-de-definition-xsd-en-php/&amp;title=Valider+un+fichier+XML+avec+un+sch%C3%A9ma+de+d%C3%A9finition+%28XSD%29+en+PHP" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="shr-comfeed">
			<a href="http://www.jonathan-petitcolas.com/valider-un-fichier-xml-avec-un-schema-de-definition-xsd-en-php/feed" rel="nofollow" class="external" title="Subscribe to the comments for this post?">Subscribe to the comments for this post?</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>

]]></content:encoded>
			<wfw:commentRss>http://www.jonathan-petitcolas.com/valider-un-fichier-xml-avec-un-schema-de-definition-xsd-en-php/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Valider un document XML avec un XSD sous Linux</title>
		<link>http://www.jonathan-petitcolas.com/valider-un-document-xml-avec-un-xsd-sous-linux/</link>
		<comments>http://www.jonathan-petitcolas.com/valider-un-document-xml-avec-un-xsd-sous-linux/#comments</comments>
		<pubDate>Sat, 15 Nov 2008 22:06:53 +0000</pubDate>
		<dc:creator>Jonathan Petitcolas</dc:creator>
				<category><![CDATA[Développement]]></category>
		<category><![CDATA[validation]]></category>
		<category><![CDATA[xml]]></category>
		<category><![CDATA[xsd]]></category>

		<guid isPermaLink="false">http://www.jonathan-petitcolas.com/?p=398</guid>
		<description><![CDATA[Article décrivant la manière de valider un fichier XML avec un fichier XSD sous Linux, grâce à l'utilitaire xmllint.]]></description>
			<content:encoded><![CDATA[<p>Lors de la rédaction d'un fichier XML, il est très fortement conseillé de créer un fichier de validation, afin de s'assurer que la syntaxe du document est rigoureusement respectée. Pour ce faire, on peut soit utiliser des DTD (<em>Document Type Definition</em>) ou des XSD (<em>XML Schema Definition</em>). Les XSD ont l'avantage d'être beaucoup plus simple à écrire. </p>
<p>Il est possible de vérifier la validité du document XSD avec le <a href="http://validator.w3.org">validateur du W3C</a>, ainsi que celle du XML, il n'est en revanche pas possible de vérifier les liens entre le XML et le XSD : telle balise possède-t-elle bien les bons attributs ? les bons noeuds enfants ? Il nous faut donc un outil se basant sur notre XSD. Il s'agit de <em>xmllint</em>.</p>
<p>Cette commande, qui possède aussi d'autres fonctionnalités, s'utilise de la façon suivante :</p>
<blockquote><p>$ xmllint --noout blog.xml --schema blog.xsd</p></blockquote>
<p>Vous aurez alors une liste d'erreurs éventuelles, qu'en tant que bon développeur vous vous empresserez de corriger. ;)</p>


<div class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-center shr-bookmarks-bg-knowledge">
<ul class="socials">
		<li class="shr-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://www.jonathan-petitcolas.com/valider-un-document-xml-avec-un-xsd-sous-linux/&amp;t=Valider+un+document+XML+avec+un+XSD+sous+Linux" rel="nofollow" class="external" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="shr-twitter">
			<a href="http://twitter.com/home?status=Jonathan+Petitcolas+%3A+Valider+un+document+XML+avec+un+XSD+sous+Linux+-+http://tinyurl.com/mdb4sp&amp;source=shareaholic" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="shr-netvibes">
			<a href="http://www.netvibes.com/share?title=Valider+un+document+XML+avec+un+XSD+sous+Linux&amp;url=http://www.jonathan-petitcolas.com/valider-un-document-xml-avec-un-xsd-sous-linux/" rel="nofollow" class="external" title="Submit this to Netvibes">Submit this to Netvibes</a>
		</li>
		<li class="shr-linkedin">
			<a href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http://www.jonathan-petitcolas.com/valider-un-document-xml-avec-un-xsd-sous-linux/&amp;title=Valider+un+document+XML+avec+un+XSD+sous+Linux&amp;summary=Article%20d%C3%A9crivant%20la%20mani%C3%A8re%20de%20valider%20un%20fichier%20XML%20avec%20un%20fichier%20XSD%20sous%20Linux%2C%20gr%C3%A2ce%20%C3%A0%20l%27utilitaire%20xmllint.&amp;source=Blog de Jonathan Petitcolas" rel="nofollow" class="external" title="Share this on LinkedIn">Share this on LinkedIn</a>
		</li>
		<li class="shr-googlebuzz">
			<a href="http://www.google.com/buzz/post?url=http://www.jonathan-petitcolas.com/valider-un-document-xml-avec-un-xsd-sous-linux/&amp;imageurl=" rel="nofollow" class="external" title="Post on Google Buzz">Post on Google Buzz</a>
		</li>
		<li class="shr-googlereader">
			<a href="http://www.google.com/reader/link?url=http://www.jonathan-petitcolas.com/valider-un-document-xml-avec-un-xsd-sous-linux/&amp;title=Valider+un+document+XML+avec+un+XSD+sous+Linux&amp;srcUrl=http://www.jonathan-petitcolas.com/valider-un-document-xml-avec-un-xsd-sous-linux/&amp;srcTitle=Valider+un+document+XML+avec+un+XSD+sous+Linux&amp;snippet=Article%20d%C3%A9crivant%20la%20mani%C3%A8re%20de%20valider%20un%20fichier%20XML%20avec%20un%20fichier%20XSD%20sous%20Linux%2C%20gr%C3%A2ce%20%C3%A0%20l%27utilitaire%20xmllint." rel="nofollow" class="external" title="Add this to Google Reader">Add this to Google Reader</a>
		</li>
		<li class="shr-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://www.jonathan-petitcolas.com/valider-un-document-xml-avec-un-xsd-sous-linux/&amp;title=Valider+un+document+XML+avec+un+XSD+sous+Linux" rel="nofollow" class="external" title="Digg this!">Digg this!</a>
		</li>
		<li class="shr-delicious">
			<a href="http://delicious.com/post?url=http://www.jonathan-petitcolas.com/valider-un-document-xml-avec-un-xsd-sous-linux/&amp;title=Valider+un+document+XML+avec+un+XSD+sous+Linux" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="shr-comfeed">
			<a href="http://www.jonathan-petitcolas.com/valider-un-document-xml-avec-un-xsd-sous-linux/feed" rel="nofollow" class="external" title="Subscribe to the comments for this post?">Subscribe to the comments for this post?</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>

]]></content:encoded>
			<wfw:commentRss>http://www.jonathan-petitcolas.com/valider-un-document-xml-avec-un-xsd-sous-linux/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
