Bonjour,
Ma question va certainement paraitre plus qu'idiote (peut etre pas uniquement paraitre, d'ailleurs) mais je suis un peu bloquee.
J'ai un html contenant ce type de donnees
que j'aimerais mettre dans un tableau comme ceci
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13 <div class="dataParent"> <span class="data"><span class="attribute">attributeDescription</span> <strong> 1 </strong></span> <span class="data"><span class="attribute">attributeType</span> <strong>HTDF(Pieces)</strong></span> <span class="data"><span class="attribute">attributeDescription</span> <strong> 15 </strong></span> <span class="data"><span class="attribute">attributeType</span> <strong>JUTH(Weight)</strong></span> <span class="data"><span class="attribute">attributeDescription</span> <strong> FILON </strong></span> <span class="data"><span class="attribute">attributeType</span> <strong>RCSF(First Name)</strong></span> <span class="data"><span class="attribute">attributeDescription</span> <strong> GERARD </strong></span> <span class="data"><span class="attribute">attributeType</span> <strong>THYF(Surname)</strong></span> <span class="data"><span class="attribute">attributeValue</span> <strong>4578</strong></span> <span class="data"><span class="attribute">attributeDescription</span> <strong> kg </strong></span> <span class="data"><span class="attribute">attributeType</span> <strong>UNIT(Unit)</strong></span> </div>
attributeDescription | attributeType | attributeValue
1 HTDF(Pieces)
15 JUTH(Weight)
FILON RCSF(First Name)
GERARD THYF(Surname) 4578
kg UNIT(Unit).
je sais que le mieux est sans doute XSLT mais je me sens bien plus 'a l'aise en PHP et avec DOM et je n'ai pas tres envie d'ajouter une technologie.
case_table($divElement) me renvoie, pour chaque noeud $divElement donc, le tableau associe, sous forme de string, par 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 $xpath = new DOMXpath($dom_second_step); $divElements = $xpath->query('//*/div'); if (!is_null($divElements)) { foreach ($divElements as $divElement) { $spanData=$divElement->firstChild; $spanDatas = $divElement->childNodes; $flagJustDatas=true; foreach ($spanDatas as $spanData) { if ($spanData->nodeName!="span") {$flagJustDatas=false;}; } if ($flagJustDatas==true){ if (case_table($divElement)!=""){ $newElement=case_table($divElement); //newElement is a string $displayNode=new DOMDocument; $displayNode->preserveWhiteSpace = false; $displayNode->formatOutput = true; $displayNode->loadXml($newElement); $newNode = $displayNode->importNode($divElement->parentNode, true); $divElement->parentNode->replaceChild($newNode, $divElement); //ligne 262: la ligne de l'erreur //$displayNode=$displayNode->getElementsByTagName("span")->item(0); } } } } //echo htmlentities($dom_second_step->saveXML()); echo $dom_second_step->saveXML();
et voici le message d'erreur qui s'affiche:
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 <span class="modifiedData"> <table> <tr> <th>attributeDescription:</th> <th>attributeType: </th> </tr> <tr> <td> 1 </td> <td> YUIBK</td> </tr> <tr> <td> 15 </td> <td> RGJK</td> </tr> <tr> <td> GERARD </td> <td> GHT(First Name)</td> </tr> <tr> <td> FILON </td> <td> THG(Surname)</td> </tr> <tr> <td> kg </td> <td> UNIT(Unit)</td> </tr> </table> </span>.
J'aimerais afficher le resultat du parsage, avec les tableaux remplacant les span, la fonction case_table qui pour un noeud renvoie le string retourne fonctionne bien, mais je n'arrive pas 'a remplacer le vieux noeud par ce nouveau.Fatal error: Uncaught exception 'DOMException' with message 'Wrong Document Error' in mainFile.php:262 Stack trace: #0 mainFile.php(262): DOMNode->replaceChild(Object(DOMElement), Object(DOMElement)) #1 mainFile.php(396): main_parsage_message() #2 {main} thrown in mainFile.php on line 262
J'espere avoir ete la plus claire possible.
Merci beaucoup d'avance 'a celui qui voudra bien se plonger dans mon code!
Partager