IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Bibliothèques et frameworks PHP Discussion :

[XML] parcourir le dom


Sujet :

Bibliothèques et frameworks PHP

  1. #1
    Membre à l'essai
    Homme Profil pro
    Développeur Web
    Inscrit en
    Janvier 2013
    Messages
    17
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Suisse

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Janvier 2013
    Messages : 17
    Points : 16
    Points
    16
    Par défaut [XML] parcourir le dom
    Bonjour mon but est de mettre une feuille libreoffice calcul dans un dossier sur le serveur.La renommer en .zip et d'extraire content.xml. Jusqu'à la pas problème j'y suis arrivé. J'arrive à mettre l'arbre dom de content.xml dans ma page...mais n'arrive à le parcourir.
    J'aimerais le parcourir, mettre chaque lignes et colonnes dans une base de donnée et ensuite pouvoir l'afficher en html
    Voici mon code
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    <!DOCTYPE html>
    <html>
    	<head>
    		<title>Les Glaces du Lac - Rentabilité</title>
    		<meta charset="UTF-8" />
    	</head>
    	<body>
    		<form action="index.php" method="post" enctype="multipart/form-data">
    			<input type="file" name="file" />
    			<input type="submit" />
    		</form>
    		<?php
     
    		if (isset($_FILES['file'])) {
    			if ($_FILES['file']['error'] == 0) {
     
    				if ($_FILES['file']['size'] <= 1000000) {
     
    					$infosfichier = pathinfo($_FILES['file']['name']);
    					$extension_upload = $infosfichier['extension'];
    					$extensions_autorisees = array('ods');
    					if (in_array($extension_upload, $extensions_autorisees)) {
     
    						move_uploaded_file($_FILES['file']['tmp_name'], 'uploads/' . basename($_FILES['file']['name']));
    						echo "L'envoi a bien été effectué !";
    						$adress = "./uploads/" . $_FILES["file"]["name"];
     
    						$element['filename'] = $_FILES["file"]["name"];
    						$element["extension"] = "zip";
    						$nomAvecExt = "./uploads/" . $element['filename'] . '.' . $element['extension'];
     
    						rename($adress, $nomAvecExt);
    						$zip = new ZipArchive;
    						$res = $zip -> open($nomAvecExt);
    						if ($res === TRUE) {
    							$zip -> extractTo("./uploads/", array('content.xml'));
    							$zip -> close();
    							$doc = new DOMDocument();
    							$doc -> load("./uploads/content.xml");
    							echo $doc -> saveXML();
     
    							$text = $doc -> getElementsByTagName('text:p');
    							foreach ($text as $text) {
    								echo $text -> nodeValue, PHP_EOL;
    							}
    						} else {
    							echo 'échec';
    						}
    					}
    				}
    			}
    		}
    		?>
    	</body>
    </html>
    pouvez vous m'aider svp
    Merci et bonne soirée

  2. #2
    Membre à l'essai
    Homme Profil pro
    Développeur Web
    Inscrit en
    Janvier 2013
    Messages
    17
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Suisse

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Janvier 2013
    Messages : 17
    Points : 16
    Points
    16
    Par défaut
    Re la question que je me pose, sur le style de contenu que j'obtient

    voici un exemple :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    <?xml version="1.0" encoding="UTF-8"?>
    <office:document-content xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" xmlns:presentation="urn:oasis:names:tc:opendocument:xmlns:presentation:1.0" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" xmlns:math="http://www.w3.org/1998/Math/MathML" xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" xmlns:ooo="http://openoffice.org/2004/office" xmlns:ooow="http://openoffice.org/2004/writer" xmlns:oooc="http://openoffice.org/2004/calc" xmlns:dom="http://www.w3.org/2001/xml-events" xmlns:xforms="http://www.w3.org/2002/xforms" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:rpt="http://openoffice.org/2005/report" xmlns:of="urn:oasis:names:tc:opendocument:xmlns:of:1.2" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:grddl="http://www.w3.org/2003/g/data-view#" xmlns:tableooo="http://openoffice.org/2009/table" xmlns:field="urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0" xmlns:formx="urn:openoffice:names:experimental:ooxml-odf-interop:xmlns:form:1.0" xmlns:css3t="http://www.w3.org/TR/css3-text/" office:version="1.2">
    	<office:scripts/>
    	<office:font-face-decls>
    		<style:font-face style:name="Liberation Sans" svg:font-family="&apos;Liberation Sans&apos;" style:font-family-generic="swiss" style:font-pitch="variable"/>
    		<style:font-face style:name="DejaVu Sans" svg:font-family="&apos;DejaVu Sans&apos;" style:font-family-generic="system" style:font-pitch="variable"/>
    		<style:font-face style:name="Droid Sans Fallback" svg:font-family="&apos;Droid Sans Fallback&apos;" style:font-family-generic="system" style:font-pitch="variable"/>
    		<style:font-face style:name="Lohit Hindi" svg:font-family="&apos;Lohit Hindi&apos;" style:font-family-generic="system" style:font-pitch="variable"/>
    	</office:font-face-decls>
    	<office:automatic-styles>
    		<style:style style:name="co1" style:family="table-column">
    			<style:table-column-properties fo:break-before="auto" style:column-width="3.602cm"/>
    		</style:style>
    		<style:style style:name="co2" style:family="table-column">
    			<style:table-column-properties fo:break-before="auto" style:column-width="2.258cm"/>
    		</style:style>
    		<style:style style:name="ro1" style:family="table-row">
    			<style:table-row-properties style:row-height="0.427cm" fo:break-before="auto" style:use-optimal-row-height="true"/>
    		</style:style>
    		<style:style style:name="ro2" style:family="table-row">
    			<style:table-row-properties style:row-height="0.452cm" fo:break-before="auto" style:use-optimal-row-height="true"/>
    		</style:style>
    		<style:style style:name="ta1" style:family="table" style:master-page-name="Default">
    			<style:table-properties table:display="true" style:writing-mode="lr-tb"/>
    		</style:style>
    	</office:automatic-styles>
    	<office:body>
    		<office:spreadsheet>
    			<table:table table:name="Feuille1" table:style-name="ta1">
    				<table:table-column table:style-name="co1" table:default-cell-style-name="Default"/>
    				<table:table-column table:style-name="co2" table:number-columns-repeated="2" table:default-cell-style-name="Default"/>
    				<table:table-row table:style-name="ro1">
    					<table:table-cell office:value-type="string">
    						<text:p>nom</text:p>
    					</table:table-cell>
    					<table:table-cell office:value-type="string">
    						<text:p>prénom</text:p>
    					</table:table-cell>
    					<table:table-cell office:value-type="string">
    						<text:p>age</text:p>
    					</table:table-cell>
    				</table:table-row>
    				<table:table-row table:style-name="ro1">
    					<table:table-cell office:value-type="string">
    						<text:p>mickael</text:p>
    					</table:table-cell>
    					<table:table-cell office:value-type="string">
    						<text:p>Anthony</text:p>
    					</table:table-cell>
    					<table:table-cell office:value-type="float" office:value="18">
    						<text:p>18</text:p>
    					</table:table-cell>
    				</table:table-row>
    				<table:table-row table:style-name="ro1">
    					<table:table-cell office:value-type="string">
    						<text:p>Stéphane</text:p>
    					</table:table-cell>
    					<table:table-cell office:value-type="string">
    						<text:p>pierre</text:p>
    					</table:table-cell>
    					<table:table-cell office:value-type="float" office:value="22">
    						<text:p>22</text:p>
    					</table:table-cell>
    				</table:table-row>
    			</table:table>
    			<table:named-expressions/>
    		</office:spreadsheet>
    	</office:body>
    </office:document-content>

    Bon la c'est un simple exemple, d'habitude il est sous forme de bloc condenser mais la je l'ai mi en forme pour plus de lisibilité

    on voit que les information sont en namespace par exemple text:p

    je n'arrive pas a parcourir se type de balise

  3. #3
    Membre à l'essai
    Homme Profil pro
    Développeur Web
    Inscrit en
    Janvier 2013
    Messages
    17
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Suisse

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Janvier 2013
    Messages : 17
    Points : 16
    Points
    16
    Par défaut
    Alors je vien s d'essayer getElementsByTagNameNs mais bon rien de plus

  4. #4
    Membre émérite Avatar de tsuji
    Inscrit en
    Octobre 2011
    Messages
    1 558
    Détails du profil
    Informations forums :
    Inscription : Octobre 2011
    Messages : 1 558
    Points : 2 736
    Points
    2 736
    Par défaut
    $text = $doc -> getElementsByTagName('text:p');
    Comme ça.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    $text = $doc -> getElementsByTagNameNS('urn:oasis:names:tc:opendocument:xmlns:text:1.0', 'p');

Discussions similaires

  1. [DOM XML] Migration script DOM vers DOMXML
    Par Fabouney dans le forum Bibliothèques et frameworks
    Réponses: 2
    Dernier message: 03/10/2006, 10h46
  2. [C#] XML -> parcourir des noeuds un après l'autre ?
    Par TheParadoX dans le forum Windows Forms
    Réponses: 2
    Dernier message: 04/09/2006, 17h14
  3. [DOM XML] Comment utiliser DOM(XML)?
    Par hitman94 dans le forum Bibliothèques et frameworks
    Réponses: 2
    Dernier message: 27/07/2006, 16h16
  4. [DOM XML] Utilisation de DOM/DomXML
    Par m@t dans le forum Bibliothèques et frameworks
    Réponses: 6
    Dernier message: 13/02/2006, 11h22

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo