parser xml xsl

Répondre


Cette question est un moyen d’empêcher des soumissions automatisées de formulaires par des robots.
Smileys
:D :) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :!: :?: :idea: :arrow: :| :mrgreen: =D> #-o =P~ :^o :non: :priere: 8-|
Voir plus de smileys
  Revue du sujet
 

  Étendre la vue Revue du sujet : parser xml xsl

Re: parser xml xsl

par hypo » 10 janv. 2011, 19:40

alors tout d'abord merci de ta grande patience, cela focntionne avec ton dernier code + une modification sur le script d'appel

j'ai rajouté ceci

Code : Tout sélectionner

get_bloginfo('url').
sur "/servicepublic/stylesheets/"
     
<?php

if(!isset($_GET[xml])){
$xml="http://lecomarquage.service-public.fr/xml2v2/N358.xml";
}
else{
$xml="http://lecomarquage.service-public.fr/xml2v2/".$_GET[xml];
}
if(!isset($_GET[xsl])){
$xsl=get_bloginfo('url')."/servicepublic/Stylesheets/spNoeud.xsl";
}
else{
$xsl=get_bloginfo('url')."/servicepublic/Stylesheets/".$_GET[xsl];
}
 
$REFERER="?"; 
$IMAGES=get_bloginfo('url')."/servicepublic/images/";
$XMLURL="http://lecomarquage.service-public.fr/xml2v2/";
$CATEGORIE="particuliers"; 
$PIVOTS=""; 

echo (do_shortcode('[XmlProcessor xml="'.$xml.'" xslt="'.$xsl.'" params="XMLURL='.$XMLURL.'|REFERER='.$REFERER.'|PIVOTS='.$PIVOTS.'|CATEGORIE='.$CATEGORIE.'|IMAGES='.$IMAGES.'"]'));


?> 
merci encore mille fois :)

Re: parser xml xsl

par stealth35 » 10 janv. 2011, 19:30

juste avant if ($xml_exist && $xslt_exist)

fait
var_dump($xml_exist, $xslt_exist);
et montre ton nouveau code complet :wink:

Re: parser xml xsl

par hypo » 10 janv. 2011, 19:27

oui malheureusemennt :(

Re: parser xml xsl

par stealth35 » 10 janv. 2011, 19:25

et toujours la même erreurs ?

Re: parser xml xsl

par hypo » 10 janv. 2011, 19:24

voici suite au changement :

Code : Tout sélectionner

string(10) "/home/www/" string(53) "http://lecomarquage.service-public.fr/xml2v2/N358.xml" string(47) "/home/www/servicepublic/Stylesheets/spNoeud.xsl"

Re: parser xml xsl

par stealth35 » 10 janv. 2011, 19:01

string(10) "/home/www/" string(53) "http://lecomarquage.service-public.fr/xml2v2/N358.xml" string(47) "/home/www/servicepublic/Stylesheets/spNoeud.xsl"
j'ai éditer mon message au dessus :wink:

visiblement les paths on l'air corrects non ?

Re: parser xml xsl

par hypo » 10 janv. 2011, 18:56

string(10) "/home/www/" string(53) "http://lecomarquage.service-public.fr/xml2v2/N358.xml" string(47) "/home/www/servicepublic/Stylesheets/spNoeud.xsl"

Re: parser xml xsl

par stealth35 » 10 janv. 2011, 18:53

montre avec le var_dump() plutôt

EDIT : le problème doit venir du file_exists ca marche pas avec les URL
if(!preg_match('/^https?:\/\//', $xml))
                {
                	$xml  = $path . $xml;
                	$xml_exist = file_exists($xml);
                }
                else
                {
                	$xml_exist = true;
                }
                             
                if(!preg_match('/^https?:\/\//', $xslt))
                {
                	$xslt = $path . $xslt;
                	$xml_exist = file_exists($xslt);
                }
                else
                {
                	$xslt_exist = true;
                }
                
                       
                if ($xml_exist && $xslt_exist)

Re: parser xml xsl

par hypo » 10 janv. 2011, 18:51

voici l'erreur affiché désormais...

Code : Tout sélectionner

Error processing XML and XSLT. Configuration was: Array ( [xml] => http://lecomarquage.service-public.fr/xml2v2/N358.xml [xslt] => servicepublic/Stylesheets/spNoeud.xsl [params] => XMLURL=http://lecomarquage.service-public.fr/xml2v2/|REFERER=?|PIVOTS=|CATEGORIE=particuliers|IMAGES=http://p650.phpnet.org/servicepublic/images/ )

Re: parser xml xsl

par stealth35 » 10 janv. 2011, 18:44

essaye comme ca
$path = ABSPATH;
                
if(!preg_match('/^https?:\/\//', $xml))
{
    $xml  = $path . $xml;
}
                             
if(!preg_match('/^https?:\/\//', $xslt))
{
    $xslt = $path . $xslt;
}

Re: parser xml xsl

par hypo » 10 janv. 2011, 18:30

j'ai cette erreur qui s'affiche suite à la modification :

Code : Tout sélectionner

string(10) "/home/www/" string(63) "/home/www/http://lecomarquage.service-public.fr/xml2v2/N358.xml" string(47) "/home/www/servicepublic/Stylesheets/spNoeud.xsl"

Re: parser xml xsl

par stealth35 » 10 janv. 2011, 18:26

fait :
$path = ABSPATH;
               
$xml  = $path . $xml;
$xslt = $path . $xslt;

var_dump($path, $xml, $xslt);
exit;

Re: parser xml xsl

par hypo » 10 janv. 2011, 18:19

mais ton code il sort d'où ?
<?php

if(!isset($_GET[xml])){
$xml="http://lecomarquage.service-public.fr/xml2v2/N358.xml";
}
else{
$xml="http://lecomarquage.service-public.fr/xml2v2/".$_GET[xml];
}
if(!isset($_GET[xsl])){
$xsl="servicepublic/Stylesheets/spNoeud.xsl";
}
else{
$xsl="servicepublic/Stylesheets/".$_GET[xsl];
}
 
$REFERER="?"; 
$IMAGES=get_bloginfo('url')."/servicepublic/images/";
$XMLURL="http://lecomarquage.service-public.fr/xml2v2/";
$CATEGORIE="particuliers"; 
$PIVOTS=""; 

echo (do_shortcode('[XmlProcessor xml="'.$xml.'" xslt="'.$xsl.'" params="XMLURL='.$XMLURL.'|REFERER='.$REFERER.'|PIVOTS='.$PIVOTS.'|CATEGORIE='.$CATEGORIE.'|IMAGES='.$IMAGES.'"]'));


?> 
et voici le script XMLProcessor :
<?php
/*
Plugin Name: Xslt Processor
Plugin URI: no uri at the moment
Description: The plugin aims to allow XML document transformed through XSLT to be outputted in a WordPress Page. It also now allows to pass parameters to the XSL doc
Version: 0.5
Author: Chryzo, Hakre
Author URI: http://www.chryzo.net

Copyright 2009  Chryzo  (email : [email protected])

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/

/*
usage:

	[XmlProcessor xml="xml_filepath" xslt="xslt_filepath"]
	
		xml_filepath and xslt_filepath is relative to wordpress root directory

	[XmlProcessor filepath]
	
		filepath stands for both filenames (.xml and .xsl) without the
		file extension and relative to wordpress root directory

	[XmlProcessor filepath get="key|ns=key" post="key|ns=key"]

		get / post stands for the parameters that need to be passed to the xsl document but are taken from the HTML methods

examples without parameters:

	[XmlProcessor wp-content/plugins/CPT_XslProcessor/example]
	
	[XmlProcessor xml="wp-content/plugins/CPT_XslProcessor/example.xml" xslt="wp-content/plugins/CPT_XslProcessor/example.xsl"]
	
		Both Examples work the same, they will process example.xml and
		example.xsl located in the wordpress root directory.

examples with parameters:

	[XmlProcessor wp-content/plugins/CPT_XslProcessor/example]
	
	[XmlProcessor xml="wp-content/plugins/CPT_XslProcessor/example.xml" xslt="wp-content/plugins/CPT_XslProcessor/example.xsl"]
	
		Both Examples work the same, they will process example.xml and
		example.xsl located in the wordpress root directory.	
		

*/

add_option("CPT_Path", "");
add_option("CPT_Separator", ",");

/**
 * XmlProcessor Option retrieval
 *
 *	XML - XSLT Processor
 *
 *
 * @return array list of path to look inside to retrieve files
 */
function cpt_retrieve_option() {
	$paths = get_option("CPT_Path");
	$separator = get_option("CPT_Separator");
}
 

/**
 * XmlProcessor Shortcode Hook
 * 
 * XML - XSLT Processor
 * 
 * @param  array $atts shortcode attributes
 * @return string output of shortcode(processed xml/xslt or error message on failure)
 */
function cpt_process_xml($atts) {
	
	$options = null;
	$get =null;
	$post = null;
	$namespace = null;
	$xml = false;
	$xslt = false;
	$paramSep = "|";
	$keyvalSep = "=";
	
	if (isset($atts[0])) {						// one parameter for naming both files
		$xml  = sprintf('%s.xml', $atts[0]);
		$xslt = sprintf('%s.xsl', $atts[0]);
	} elseif (isset($atts["xml"]) && isset($atts["xslt"])) {	// name xml and xslt files with an attribute on it's own.
		$xml = $atts["xml"];
		$xslt = $atts["xslt"];
	}
	
	// This is a separate section because we can't use the short format of the filepath in this case since the parameters may have
	// some blanks in them which would screw around with the parsing
	if (isset($atts["params"])){				// parameter for the parameters of the xsl file
		$options = $atts["params"];
	}
	if (isset($atts["get"])){
		$get = $atts["get"];
	}
	
	if (isset($atts["post"])){
		$get = $atts["post"];
	}
		
	if ($xml !== false)
	{	
		// this will include relative to this file
		//$path = dirname(__FILE__);
		// this will include relative to this wordpress root folder
		$path = ABSPATH;
		
		$xml  = $path . $xml;
		$xslt = $path . $xslt;
			
		if (file_exists($xml) && file_exists($xslt))
		{
			$xslDoc = new DOMDocument();
			$xslDoc->load($xslt);
			
			$xmlDoc = new DOMDocument();
			$xmlDoc->load($xml);
	
			$proc = new XSLTProcessor();
			// setting parameters section
			// /*
			if ($options != null) {
				$options = explode($paramSep,$options);
				//print_r(count($options));
				for ($i = 0; $i< count($options); $i++){
					$pair = explode($keyvalSep, $options[$i]);
					if ( count($pair) == 1 ) {
						$proc->setParameter(null, $pair[0], "");			// just a key, then we blank the value of the parameter
					} elseif ( count($pair) == 2 ) {
						//print_r($pair);
						//$proc->setParameter(null, 'default_param', 'test');		// just a key/value pair, we replace
						$proc->setParameter(null, $pair[0], $pair[1]);		// just a key/value pair, we replace
					} elseif (count($pair) == 3 ) {
						$proc->setParameter($pair[0], $pair[1], $pair[2]);	// a namespace/key/value set, we replace
					}
				}
			}
			if ($get != null) {
				$get = explode($paramSep,$get);
				for ($i = 0; $i< count($get); $i++){
					$pair = explode($keyvalSep, $get[$i]);
					if ( count($pair) == 1 ) {
						$proc->setParameter(null, $pair[0], $_GET[$pair[0]]);	// just a key, then we blank the value of the parameter
					} elseif ( count($pair) == 2 ) {
						$proc->setParameter(null, $pair[0], $_GET[$pair[1]]);	// just a key/value pair, we replace
					} elseif (count($pair) == 3 ) {
						$proc->setParameter($pair[0], $pair[1], $_GET[$pair[2]]);// a namespace/key/value set, we replace
					}
				}
			}
			if ($post != null) {
				$post = explode($paramSep,$post);
				for ($i = 0; $i< count($post); $i++){
					$pair = explode($keyvalSep, $post[$i]);
					if ( count($pair) == 1 ) {
						$proc->setParameter(null, $pair[0], $_POST[$pair[0]]);	// just a key, then we blank the value of the parameter
					} elseif ( count($pair) == 2 ) {
						$proc->setParameter(null, $pair[0], $_POST[$pair[1]]);	// just a key/value pair, we replace
					} elseif (count($pair) == 3 ) {
						$proc->setParameter($pair[0], $pair[1], $_POST[$pair[2]]);// a namespace/key/value set, we replace
					}
				}
			}
			// */
			// end of parameter section
			$proc->importStylesheet($xslDoc);			
			return $proc->transformToXML($xmlDoc);		
		}
	}
	
	return sprintf('<div class="error"><strong>Error processing XML and XSLT. Configuration was: %s</strong></div>', htmlspecialchars(print_r($atts, true)));	
}

if (function_exists("add_shortcode")){
	add_shortcode("XmlProcessor", "cpt_process_xml");
}

?>
c'est ce 2ème qui faudrait modifier

Re: parser xml xsl

par stealth35 » 10 janv. 2011, 18:13

mais ton code il sort d'où ?

Re: parser xml xsl

par hypo » 10 janv. 2011, 18:00

lorsque que tu changes des fichiers externe a quoi correspond ?
$path = ABSPATH;
$xml  = $path . $xml;
$xslt = $path . $xslt;
si je mets l'url distante j'ai cette erreur :

Code : Tout sélectionner

Error processing XML and XSLT. Configuration was: Array ( [xml] => http://lecomarquage.service-public.fr/xml2v2/N358.xml [xslt] => servicepublic/Stylesheets/spNoeud.xsl [params] => XMLURL=http://lecomarquage.service-public.fr/xml2v2/|REFERER=?|PIVOTS=|CATEGORIE=particuliers|IMAGES=http://p650.phpnet.org/servicepublic/images/ )