j'essai de parser un fichier xml (issu d'un docx) avec simpleXml. Mon fichier contient pleins de namespaces, et j'utilise xpath pour gérer celà.
voilà ce que je fais:
if (!file_exists($xml))
{
echo "Le document XML n'existe pas";
}
else
{
//chargement du fichier XML
$fichierXml = simplexml_load_file($xml);
foreach($fichierXml->xpath('//w:body/w:p') as $r)
{
$corps=$r->children("http://schemas.openxmlformats.org/wordprocessingml/2006/main");
//error_log("corps: $corps");
foreach($corps->xpath('//w:r') as $rw)
{
$wr = $rw->children("http://schemas.openxmlformats.org/wordprocessingml/2006/main");
//error_log("wr: $wr");
echo "$wr<br>";
}
}
}
j'arrive à afficher tout le contenu de mon fichier (j'aurai d'ailleurs une autre question après ce problème par rapport à ça), mais il me fait un warning, et plante au bout de quelques rafraîchissements. Voilà mon error_log:
Et pourtant dans mon document.xml, j'ai bien[23-Aug-2011 09:51:46] PHP Stack trace:
[23-Aug-2011 09:51:46] PHP 1. {main}() C:\wampServer2\www\importation\index.php:0
[23-Aug-2011 09:51:46] PHP 2. SimpleXMLElement->xpath() C:\wampServer2\www\importation\index.php:28
[23-Aug-2011 09:51:46] PHP Warning: SimpleXMLElement::xpath() [<a href='simplexmlelement.xpath'>simplexmlelement.xpath</a>]: xmlXPathEval: evaluation failed in C:\wampServer2\www\importation\index.php on line 28
[23-Aug-2011 09:51:46] PHP Stack trace:
[23-Aug-2011 09:51:46] PHP 1. {main}() C:\wampServer2\www\importation\index.php:0
[23-Aug-2011 09:51:46] PHP 2. SimpleXMLElement->xpath() C:\wampServer2\www\importation\index.php:28
[23-Aug-2011 09:51:46] PHP Warning: Invalid argument supplied for foreach() in C:\wampServer2\www\importation\index.php on line 28
[23-Aug-2011 09:51:46] PHP Stack trace:
[23-Aug-2011 09:51:46] PHP 1. {main}() C:\wampServer2\www\importation\index.php:0
[23-Aug-2011 09:51:46] PHP Warning: SimpleXMLElement::xpath() [<a href='simplexmlelement.xpath'>simplexmlelement.xpath</a>]: Undefined namespace prefix in C:\wampServer2\www\importation\index.php on line 28
[23-Aug-2011 09:51:46] PHP Stack trace:
[23-Aug-2011 09:51:46] PHP 1. {main}() C:\wampServer2\www\importation\index.php:0
[23-Aug-2011 09:51:46] PHP 2. SimpleXMLElement->xpath() C:\wampServer2\www\importation\index.php:28
[23-Aug-2011 09:51:46] PHP Warning: SimpleXMLElement::xpath() [<a href='simplexmlelement.xpath'>simplexmlelement.xpath</a>]: xmlXPathEval: evaluation failed in C:\wampServer2\www\importation\index.php on line 28
[23-Aug-2011 09:51:46] PHP Stack trace:
[23-Aug-2011 09:51:46] PHP 1. {main}() C:\wampServer2\www\importation\index.php:0
[23-Aug-2011 09:51:46] PHP 2. SimpleXMLElement->xpath() C:\wampServer2\www\importation\index.php:28
[23-Aug-2011 09:51:46] PHP Warning: Invalid argument supplied for foreach() in C:\wampServer2\www\importation\index.php on line 28
[23-Aug-2011 09:51:46] PHP Stack trace:
[23-Aug-2011 09:51:46] PHP 1. {main}() C:\wampServer2\www\importation\index.php:0
xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"
Merci de l'aide que vous m'apporterez!!