POO en PHP : Fonction de mise à jour de fichier XML

Discussion in 'PHP' started by kdson, Oct 29, 2007.

  1. #1
    Bonjour tlm !
    Le code suivant à partir des données receuillies d'un formulaire, permet de realiser la mise à jour d'un fichier XML existant.
    Alors sous mon serveur localhost WINNT ça marché Nikel. Par contre en utilsant le meme code sous Linux, je me suis rendu compte que l'exécution se bloque à $doc = new DOMDocument("1.0","UTF-8");.

    Ce serait un bien grand plaisir de recevoir votre assistance.
    Meilleures salutations

    public function updateXMLFile() {
    // create doctype
    echo 199999;
    $doc = new DOMDocument("1.0","UTF-8");

    $doc->load('/home/tft/greenstone/collect/viprivattest/import/comm/metadata.xml');
    //-----------------------------------------------------------------------------------------------------------------------------
    // Create a Child Element FileSet under DirectoryMetadata
    $FileSet=$doc->createElement("FileSet");
    $doc->documentElement->appendChild($FileSet);
    // Create a Child Element Texte Node ( "") for FileSet
    $FileSetText=$doc->createTextNode("");
    $FileSet->appendChild($FileSetText);
    //-----------------------------------------------------------------------------------------------------------------------------
    // Create a Child Element -> Child Element FileName
    $FileName=$doc->createElement("FileName");
    $FileSet->appendChild($FileName);
    // Create a Child Element Texte Node
    $FileNameText=$doc->createTextNode($this->name);//
    $FileName->appendChild($FileNameText);
    //-----------------------------------------------------------------------------------------------------------------------------
    // Create a Child Element -> Child Element Description
    $Description=$doc->createElement("Description");
    $FileSet->appendChild($Description);
    // Create a Child Element Texte Node
    $DescriptionText=$doc->createTextNode("");
    $Description->appendChild($DescriptionText);
    //-----------------------------------------------------------------------------------------------------------------------------
    //for ($i=0;$i<count($this->content);$i++) {
    foreach ($this->meta as $key => $value) {
    // Create a Child Element -> Child Element-> Child Element
    $Metadata[$key]=$doc->createElement("Metadata");
    $Description->appendChild($Metadata[$key]);

    // Create a Child Element Texte Node
    $MetadataText[$key]=$doc->createTextNode($value);
    $Metadata[$key]->appendChild($MetadataText[$key]);

    // create attribute node 1
    $mode = $doc->createAttribute("mode");
    $Metadata[$key]->appendChild($mode);
    // create attribute value node
    $modeValue = $doc->createTextNode("accumulate");
    $mode->appendChild($modeValue);

    // create attribute node 2
    $name = $doc->createAttribute("name");
    $Metadata[$key]->appendChild($name);
    // create attribute value node
    $nameValue = $doc->createTextNode("vi.".$key);
    $name->appendChild($nameValue);
    }
    //-----------------------------------------------------------------------------------------------------------------------------

    //echo $doc->saveXML();
    $order = $doc->save("Met.xml");
    }
     
    kdson, Oct 29, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    Please post your message in English. Chances that you find someone who speaks French, and knows the solution to whatever you're asking for are rather small. (I guess)
     
    nico_swd, Oct 29, 2007 IP
  3. kdson

    kdson Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Bonjour tlm !
    English
    This code, with data from a form, updates an XML file. The fact is that it's work properly under WINNT. But while using it under Linux the execution stops at $doc = new DOMDocument("1.0","UTF-8");.

    French
    Le code suivant à partir des données receuillies d'un formulaire, permet de realiser la mise à jour d'un fichier XML existant.
    Alors sous mon serveur localhost WINNT ça marché Nikel. Par contre en utilsant le meme code sous Linux, je me suis rendu compte que l'exécution se bloque à $doc = new DOMDocument("1.0","UTF-8");.

    Ce serait un bien grand plaisir de recevoir votre assistance.
    Meilleures salutations

    public function updateXMLFile() {
    // create doctype
    echo 199999;
    $doc = new DOMDocument("1.0","UTF-8");

    $doc->load('/home/tft/greenstone/collect/viprivattest/import/comm/metadata.xml');
    //-----------------------------------------------------------------------------------------------------------------------------
    // Create a Child Element FileSet under DirectoryMetadata
    $FileSet=$doc->createElement("FileSet");
    $doc->documentElement->appendChild($FileSet);
    // Create a Child Element Texte Node ( "") for FileSet
    $FileSetText=$doc->createTextNode("");
    $FileSet->appendChild($FileSetText);
    //-----------------------------------------------------------------------------------------------------------------------------
    // Create a Child Element -> Child Element FileName
    $FileName=$doc->createElement("FileName");
    $FileSet->appendChild($FileName);
    // Create a Child Element Texte Node
    $FileNameText=$doc->createTextNode($this->name);//
    $FileName->appendChild($FileNameText);
    //-----------------------------------------------------------------------------------------------------------------------------
    // Create a Child Element -> Child Element Description
    $Description=$doc->createElement("Description");
    $FileSet->appendChild($Description);
    // Create a Child Element Texte Node
    $DescriptionText=$doc->createTextNode("");
    $Description->appendChild($DescriptionText);
    //-----------------------------------------------------------------------------------------------------------------------------
    //for ($i=0;$i<count($this->content);$i++) {
    foreach ($this->meta as $key => $value) {
    // Create a Child Element -> Child Element-> Child Element
    $Metadata[$key]=$doc->createElement("Metadata");
    $Description->appendChild($Metadata[$key]);

    // Create a Child Element Texte Node
    $MetadataText[$key]=$doc->createTextNode($value);
    $Metadata[$key]->appendChild($MetadataText[$key]);

    // create attribute node 1
    $mode = $doc->createAttribute("mode");
    $Metadata[$key]->appendChild($mode);
    // create attribute value node
    $modeValue = $doc->createTextNode("accumulate");
    $mode->appendChild($modeValue);

    // create attribute node 2
    $name = $doc->createAttribute("name");
    $Metadata[$key]->appendChild($name);
    // create attribute value node
    $nameValue = $doc->createTextNode("vi.".$key);
    $name->appendChild($nameValue);
    }
    //-----------------------------------------------------------------------------------------------------------------------------

    //echo $doc->saveXML();
    $order = $doc->save("Met.xml");
    }[/QUOTE]
     
    kdson, Oct 29, 2007 IP
  4. Brewster

    Brewster Active Member

    Messages:
    489
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    60
    #4
    Hi

    Are you using php 5 on the linux box. The php website implies that DOMDocument is only available in php 5 - http://uk.php.net/dom

    Brew
     
    Brewster, Oct 29, 2007 IP
  5. kdson

    kdson Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Hi Brewster !
    Thanks for your reply !
    Yes I'm using Joomla with PHP 5.1.2 configuration
     
    kdson, Oct 29, 2007 IP
  6. Brewster

    Brewster Active Member

    Messages:
    489
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    60
    #6
    Can you put the following code into a file and send me the link to it please (PM if you prefer)

    <?php
    
    phpinfo();
    
    ?>
    PHP:
    Brew
     
    Brewster, Oct 29, 2007 IP
  7. kdson

    kdson Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Hi B !
    I'm now working on a server with a private IP. But what I can see while consulting PHPInfo on both WINNT and Linux Servers is that the last one do not have DOM extension what can may be explain the fact of none working. Do you know please how to update it so that it'll get DOM extension ?
    Thanks
     
    kdson, Oct 30, 2007 IP