Utilisation de la classe DOMDocument

kellimimi Messages postés 5 Date d'inscription samedi 13 mars 2010 Statut Membre Dernière intervention 12 janvier 2015 - 12 janv. 2015 à 10:21
kellimimi Messages postés 5 Date d'inscription samedi 13 mars 2010 Statut Membre Dernière intervention 12 janvier 2015 - 12 janv. 2015 à 10:24
Bonjour,
J'ai repris un code que je dois modifier mais je n'y comprends vraiment rien. A la compilation le programme tourne sans jamais s'arrêter.

Voilà le programme si vous pouvez me dire où se trouve les problème.
Merci beaucoup

<?php
//set_time_limit( 3000 );
chdir(dirname(__FILE__));

include_once("../login.php");

include_once("../commun/classes/classes.sql.php");

ini_set('display_errors', 1);


error_reporting(E_ALL);

$sql_base = new sql($the_host,$the_user,$the_pass,$the_base);



echo "<h1>Import multi</h1>";

$dom = new DomDocument(); // confère la classe DOMDocument(Représente un document HTML ou XML entier ; ce sera la racine de l'arbre document.) http://php.net/manual/fr/class.domdocument.php


$dom->load('http://jobs.contactrh.com/get/yoo7oasa0iebeiSh');



// comtage

$liste_id = '';

$liste_id2 = '';

$nb_offres_totales = 0;

$nb_offres_upd = 0;

$nb_offres_ins = 0;

$nb_nodes_1 = 0;

$nb_nodes_2 = 0;





/********* commentaire ********/
/* documentElement
C'est un attribut de convenance, qui permet un accès direct au noeud fils,
qui est l'élément document du document.

---Récupération de l'élément racine */

/********* commentaire ********/




$racine = $dom->documentElement;



$jobs = $dom->getElementsByTagName("offer");



$count = 1;

foreach($jobs as $job)

{

$nb_offres_totales++;



// mises à jour des offres



if ($job->hasAttribute("id"))


unset( $row );

$row["id"]=$job->getAttribute("id");



$where = "id = ".$row["id"];

$sql_base->delete("f_multi",$where);


foreach($job->childNodes as $dom_child) {

if ($dom_child->nodeType == XML_ELEMENT_NODE) {

if ($dom_child->childNodes->length > 1) {

$indice = $dom_child->nodeName;

$nodes = $dom_child->childNodes;

foreach( $nodes as $dom_child) {

if ($dom_child->nodeType == XML_ELEMENT_NODE)

$row[$indice."_".$dom_child->nodeName] = $dom_child->firstChild->nodeValue;
//$firstChild = $dom_child->firstChild;
// $row[$indice."_".$dom_child->nodeName] = $firstChild->nodeValue;



if ( $dom_child->hasAttribute("id") ) echo '';




}

}

$nb_nodes_1++;

}

else {


$field = $dom_child->nodeName;

if ( $dom_child->hasAttribute("id") ) {

$field.="_id";

$row[$field] = $dom_child->getAttribute("id");


}

$nb_nodes_2++;

}

}

}

$sql_base->insert2("f_multi",$row);




unset( $row2 );

$row2["EMP_TITRE"] = $row["title"];

$row2["EMP_SOCIETE"] = $row["company_name"];

$row2["EMP_EMAIL"] = $row["application_email"];

$row2["EMP_TYPE"] = $row["contract_type"];

$row2["EMP_RUBRIQUE"] = substr($row["sub_sector_id"],1);



$row2["EMP_DATE"] = date('Y-m-d');

$row2["EMP_LIEU"] = "FR".substr($row["location_postal_code"],0,2);

$row2["EMP_VILLE"] = $row["location_name"];

$row2["EMP_CP"] = $row["location_postal_code"];

$row2["EMP_KEY2"] = "m/".$row["id"];

$row2["EMP_ETUDES_DETAIL"] = $row["education_level"];

$row2["EMP_ETUDES_DETAIL"] = $row["work_experience"];



$text = str_replace(chr(10),"",$row["job_description"]);


$text = str_replace(chr(13),"",$text);

if ( $row["job_description"] != "" ) $row2["EMP_TEXTE"] = $text."<br><br>";

if ( $row["company_description"] != "" ) $row2["EMP_TEXTE"] .= "<b>La société</b><br>".$row["company_description"]."<br><br>";

if ( $row["work_experience"] != "" ) $row2["EMP_TEXTE"] .= "<b>Expérience :</b> ".$row["work_experience"]."<br>";

if ( $row["education_level"] != "" ) $row2["EMP_TEXTE"] .= "<b>Formation :</b> ".$row["education_level"]."<br>";



$where = "EMP_KEY2='". $row2["EMP_KEY2"]."'";


$sql_base->select("EMP_ID","dev_emploi",$where);

$row3 = $sql_base->db_result_ToRow();


if ( $row3["EMP_ID"] != "" ) {

$sql_base->update2("dev_emploi",$row2,$where);

$nb_offres_upd++;

$liste_id2.= $row3["EMP_ID"].', '; // nick

}

else {

$row2["EMP_ACTIF"]=1;

$sql_base->insert2("dev_emploi",$row2);


$nb_offres_ins++;

$liste_id.= $row["id"].', '; // nick

}

}



echo 'nb_offres_totales='.$nb_offres_totales.'<br />';

echo 'nb_offres_upd='.$nb_offres_upd.'<br />';

echo 'nb_offres_ins='.$nb_offres_ins.'<br />';

echo 'nb_nodes_1='.$nb_nodes_1.'<br />';

echo 'nb_nodes_2='.$nb_nodes_2.'<br />';

echo 'Listes des ID (EMP_KEY2) insérées : '.$liste_id.'<br />';

echo 'Listes des ID updatées : '.$liste_id2.'<br />';




function fileToObject($fileName) {



$dom = new DomDocument();


$dom->load($fileName);

echo "load<br>";



if (!@$dom->validate()) {

echo "erreur XML<br>";

}


$object = new stdClass();

$object->source = $fileName;


$root = $dom->documentElement;

$object->root = new stdClass();



getElement($root, $object->root);



return $object;

}



function getElement($dom_element, $object_element) {



$object_element->name = $dom_element->nodeName;


$object_element->textValue = iconv("UTF-8", "ISO-8859-1//TRANSLIT", trim($dom_element->firstChild->nodeValue)); //utf8_decode(


// Récupération des attributs

if ($dom_element->hasAttributes()) {

$object_element->attributes = array();

foreach($dom_element->attributes as $attName=>$dom_attribute) {

$object_element->attributes[$attName] = iconv("UTF-8", "ISO-8859-1//TRANSLIT", $dom_attribute->value);

}

}


if ($dom_element->childNodes->length > 1) {

$object_element->children = array();

foreach($dom_element->childNodes as $dom_child) {

if ($dom_child->nodeType == XML_ELEMENT_NODE) {

$child_object = new stdClass();

getElement($dom_child, $child_object);

array_push($object_element->children, $child_object);

}

}

}

}

?>

1 réponse

kellimimi Messages postés 5 Date d'inscription samedi 13 mars 2010 Statut Membre Dernière intervention 12 janvier 2015
12 janv. 2015 à 10:24
j'ai ça comme erreur:
iconv(): Detected an illegal character in input string in C:\wamp\www\juste1emploi\htdocs\aspi\aspi_multi.php on line 173
0
Rejoignez-nous