limite de texte entre les balises xml
Posté : 01 oct. 2005, 21:59
Bonjour à tous : un soucis me tracasse. Je travaille avec php 4.3.11 et parse correctement des fichiers "exercices" au format XML pour un affichage convenable sur un site web.
Mais quand le texte entre les balises commence à devenir long,
l'affichage pose des problèmes. Voici le code source de mon objet qui parse les fiches exo au format XML :
(dernière question à 3 points, difficulté B
=> donnée placées dans un tableau pour affichage html)
Puis-je avoir une réponse pour savoir comment afficher des textes plutôt long
entre balises XML ?
Dois-je toucher dans le php.ini ?
Est-ce un problème interne pour lequel il n'y a rien à faire ?
Merci davance pour toute reponse.
Mais quand le texte entre les balises commence à devenir long,
l'affichage pose des problèmes. Voici le code source de mon objet qui parse les fiches exo au format XML :
<?
class TEval
{
// ________________________________ Les variables internes
var $l_depth = array();
var $l_titre = "";
var $l_b_titre = FALSE;
var $l_niveau = "";
var $l_b_niveau = FALSE;
var $l_reference = "";
var $l_b_reference = FALSE;
var $l_en_tete = "";
var $l_b_en_tete = FALSE;
var $l_HQ = array();//texte, points, difficulte
var $l_nQ = 0;
var $l_TbQuestions = array();// of $HQ
var $l_b_question = FALSE;
var $l_nR = 0;
var $l_b_correction = FALSE;
var $l_TbReponses = array();
var $l_b_corrIntro = FALSE;
var $l_corrIntro = "";
var $l_b_corrFin = FALSE;
var $l_corrFIn = "" ;
var $parseur;
var $l_Somme_Points = 0;
var $l_difficulte = "";
var $l_b_difficulte = FALSE;
var $l_commentaire = "";
var $l_b_commentaire = FALSE;
// ________________________________ Constructeur
function TEval($aFile)
{
$this->parseur = xml_parser_create();
xml_set_object($this->parseur, &$this);
// association des fonctions liées au début et à la fin des élements au parseur instancié
xml_set_element_handler ($this->parseur, "StartElement", "EndElement");
// association de la fonction pour lire le contenu entre les balises
xml_set_character_data_handler ($this->parseur, "LitBalise");
// ouverture du document xml
$f = fopen ($aFile, "r");
while ($data = fread($f, filesize($aFile))) { xml_parse($this->parseur, $data, feof($f));}//4096
xml_parser_free ($this->parseur);
fclose($f);
}
// ________________________________ Fonction interne : StartElement
Function StartElement ($aParseur, $aName, $aAttrs)
{
For ($i = 0 ; $i < $this->depth[$aParseur] ; $i++)
{
if ($aName == "TITRE") { $this->l_b_titre = TRUE; }
if ($aName == "NIVEAU") {$this->l_b_niveau = TRUE;}
if ($aName == "DIFFICULTE") {$this->l_b_difficulte = TRUE; }
if ($aName == "REFERENCE") {$this->l_b_reference = TRUE;}
if ($aName == "COMMENTAIRE") {$this->l_b_commentaire = TRUE; }
if ($aName == "INTRO") {$this->l_b_en_tete = TRUE;}
if ($aName == "QUESTION")
{
$this->l_b_question = TRUE;
while (list ($key, $val) = each ($aAttrs))
{
if ($key == "POINTS")
{
$this->l_HQ["POINTS"] = $val;
$this->l_Somme_Points += $val;
}
if ($key == "DIFFICULTE") {$this->l_HQ["DIFFICULTE"] = $val;}
}// while
}// if question
if ($aName == "CORRECTION-INTRO") {$this->l_b_corrIntro = TRUE;}
if ($aName == "CORRECTION-FIN") {$this->l_b_corrFin = TRUE;}
if ($aName == "REPONSE") { $this->l_b_correction = TRUE;}
}// end for
$this->depth[$aParseur]++;
}// fin de Fonction StartElement
// ________________________________ Fonction interne : LitBalise
function LitBalise ($aParseur, $aText)
{
if ($this->l_b_titre) {$this->l_titre = TEval::crochet2chevron($aText); }
if ($this->l_b_niveau) {$this->l_niveau = $aText;}
if ($this->l_b_difficulte) {$this->l_difficulte = $aText;}
if ($this->l_b_reference) {$this->l_reference = $aText;}
if ($this->l_b_commentaire) {$this->l_commentaire = TEval::crochet2chevron($aText);}
if ($this->l_b_en_tete) {$this->l_en_tete = TEval::crochet2chevron($aText);}
if ($this->l_b_question)
{
$this->l_HQ["TEXTE"] = TEval::crochet2chevron($aText);
$this->l_TbQuestions[$this->l_nQ] = $this->l_HQ;
$this->l_nQ++;
}
if ($this->l_b_correction)
{
$this->l_TbReponses[$this->l_nR] = TEval::crochet2chevron($aText);
$this->l_nR++;
}
if ($this->l_b_corrIntro) {$this->l_corrIntro = TEval::crochet2chevron($aText);}
if ($this->l_b_corrFin) {$this->l_corrFin = TEval::crochet2chevron($aText);}
}
// ________________________________ Fonction interne : EndElement
function EndElement ($aParseur, $aName)
{
if ($aName == "TITRE") { $this->l_b_titre = FALSE; }
if ($aName == "NIVEAU") {$this->l_b_niveau = FALSE;}
if ($aName == "DIFFICULTE") {$this->l_b_difficulte = FALSE;}
if ($aName == "COMMENTAIRE") {$this->l_b_commentaire = FALSE;}
if ($aName == "REFERENCE") {$this->l_b_reference = FALSE;}
if ($aName == "INTRO") {$this->l_b_en_tete = FALSE;}
if ($aName == "QUESTION") {$this->l_HQ = array(); $this->l_b_question = FALSE;}
if ($aName == "REPONSE") {$this->l_b_correction = FALSE; }
if ($aName == "CORRECTION-INTRO") {$this->l_b_corrIntro = FALSE;}
if ($aName == "CORRECTION-FIN") {$this->l_b_corrFin = FALSE;}
$this->l_depth[$aParseur]-- ;
}// fin de EndElement
// ________________________________ Fonction interne : crochet2chevron
function crochet2chevron ($aPhrase)
{
$intermediaire = ereg_replace("\[", "<", $aPhrase);
return ereg_replace("\]", ">", $intermediaire);
}
// ________________________________ Fonction GET : get_titre
function get_titre() { return $this->l_titre; }
// ________________________________ Fonction GET : get_entete
function get_entete() { return $this->l_en_tete;}
// ________________________________ Fonction GET : get_questions
function get_questions() {return $this->l_TbQuestions ; }
// ________________________________ Fonction GET : get_correction
function get_correction() {return $this->l_correction ;}
// ________________________________ Fonction GET : get_points
function get_points() {return $this->l_Somme_Points; }
// ________________________________ Fonction GET : get_difficulte
function get_difficulte() {return $this->l_difficulte;}
// ________________________________ Fonction GET : get_niveau
function get_niveau() {return $this->l_niveau ;}
// ________________________________ Fonction GET : get_commentaire
function get_commentaire() {return $this->l_commentaire;}
// ________________________________ Fonction GET : get_reference
function get_reference() {return $this->l_reference; }
// ________________________________ Fonction GET : get_reponses
function get_reponses() {return $this->l_TbReponses ;}
// ________________________________ Fonction GET : get_corrIntro
function get_corrIntro() {return $this->l_corrIntro;}
// ________________________________ Fonction GET : get_corrFin
function get_corrFin() {return $this->l_corrFin;}
// ________________________________ Fonction GET :
}
?>
Enfin voici un extrait d'une fiche xml qui pose probleme : (dernière question à 3 points, difficulté B
=> donnée placées dans un tableau pour affichage html)
Code : Tout sélectionner
<sujet>
<intro></intro>
<question points="1" difficulte="A">En quoi consiste une voltampérométrie ?</question>
<question points="1" difficulte="A">Faire le schéma de l'expérience.</question>
<question points="3" difficulte="B">Un élève recueille les valeurs suivantes :[table width="75%" border="1"]
[tr bgcolor="#cccccc"]
[td]
[center]U[/center]
[/td]
[td]
[center]I[/center]
[/td] [td]
[center]U[/center]
[/td]
[td]
[center]I[/center]
[/td]
[/tr]
[tr bgcolor="#cccccc"]
[td]
[center]V[/center]
[/td]
[td]
[center]mA[/center]
[/td]
[td]
[center]V[/center]
[/td]
[td]
[center]mA[/center]
[/td]
[/tr]
[tr]
[td]
[center]0,49[/center]
[/td]
[td]
[center]27[/center]
[/td]
[td]
[center]2,49[/center]
[/td]
[td]
[center]139[/center]
[/td]
[/tr]
[tr]
[td]
[center]0,98[/center]
[/td]
[td]
[center]54[/center]
[/td]
[td]
[center]3,01[/center]
[/td]
[td]
[center]169[/center]
[/td]
[/tr]
[tr]
[td]
[center]1,47[/center]
[/td]
[td]
[center]82[/center]
[/td]
[td]
[center]3,49[/center]
[/td]
[td]
[center]197[/center]
[/td]
[/tr]
[tr]
[td]
[center]2[/center]
[/td]
[td]
[center]111[/center]
[/td]
[td]
[center]3,98[/center]
[/td]
[td]
[center]225[/center]
[/td]
[/tr]
[/table]
[br]Faire le graphique exprimant la tension ( en ordonnée) en fonction de l'intensité du courant électrique (en abscisse) en choisissant pour échelles (abscisses : 1 cm pour 20 mA ; ordonnées : 1 cm pour 1 V).</question>
<question points="2" difficulte="B">Déterminer la valeur globale du résistor.</question>
</sujet>Puis-je avoir une réponse pour savoir comment afficher des textes plutôt long
entre balises XML ?
Dois-je toucher dans le php.ini ?
Est-ce un problème interne pour lequel il n'y a rien à faire ?
Merci davance pour toute reponse.