1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
| <?php
$connexion = mysql_connect("localhost", "root", "") or die("connexion impossible") ;
$db = mysql_select_db("dubois", $connexion) or die("selection impossible") ;
echo "test...";
class tag
{
var $chemin="";
var $chapitre;
var $localisation;
var $para_section;
var $para_soussection;
var $paragraphe;
#var $tab_localisation=array(); #recuperer le contenu dans un tableau pour que ce soit plus propre
#création du parser
function startElement($sax, $nom, $attributs)
{
var_dump($sax, $nom, $attributs);
$this->chemin .="/".$nom;
if ($this->chemin=="html/body")
{
$this->chapitre = "";
$this->localisation = "";
$this->para_section = "";
$this->para_soussection = "";
$this->paragraphe = "";
}
}
function endElement($sax, $nom)
{
if ($this->chemin=="body")
{
$chapitre = ($this->chapitre);
$localisation = ($this->localisation);
$para_section = ($this->para_section);
$para_soussection = ($this->para_soussection);
$para_paragraphe = ($this->para_paragraphe);
}
$pos = strpos($this->chemin, "/");
$this->chemin = substr ($this->chemin, 0, $pos);
}
function texte ($sax, $texte)
{
if ($this->chemin=="/chapitre")
{
$this->chapitre .=$texte;
$req="INSERT INTO localisation( Chapitre )
VALUES ('$this->chapitre')";
error_reporting();
$res = mysql_query($req);
}
elseif ($this->chemin=="/body/localisation")
{
$this->localisation .=$texte;
}
elseif ($this->chemin=="/body/localisation/para_section")
{
$this->para_section .=$texte;
}
elseif ($this->chemin=="/body/localisation/para_soussection")
{
$this->para_soussection .=$texte;
}
elseif ($this->chemin=="/body/localisation/para_paragraphe")
{
$this->para_paragraphe .=$texte;
}
}
}
function xml_result()
{
global $tag;
$tag = new tag();
#$tab=$xml->tab_localisation;
$sax=xml_parser_create("UTF-8");
xml_set_object ($sax, $tag);
xml_parser_set_option ($sax, XML_OPTION_CASE_FOLDING, FALSE);
xml_set_character_data_handler ($sax, "xml_result");
xml_set_element_handler ($sax, "starElement", "endElement");
$fichier = "localisation1-xml.xml";
$fp = fopen($fichier, "r");
while ($xml = fread ($fp, 1024))
{
if (!xml_parse($sax, $xml, true))
{
printf("Erreur XML : %s à la ligne %d lors du traitement de l'entité %s\n",
xml_error_string($sax),
xml_get_current_line_number($sax),
xml_get_error_code ($sax),
$openEntityNames);
xml_parser_free($sax);
return FALSE;
}
xml_parse ($sax, $xml, feof($fp));
}
}
/*function requete()
{
#Faire une condition par ex si la balise ouvrante est chapitre alors :
$req="INSERT INTO localisation( Chapitre )
VALUES ('$this->chapitre')";
error_reporting();
$res = mysql_query($req);
$db->debug();
}*/
xml_result();
#requete();
echo "...test";
?> |
Partager