Salut, a tous je tente de realise un parsage de fichier XML que je recupere d'une machine sur le reseau, mais j'ai quelques soucis...
Code :
- <?xml version="1.0" encoding="UTF-8" ?>
- - <runtime-data xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="file:cli_show_output.xsd" display-level="normal">
- - <hierarchy name="show" type="static">
- - <hierarchy name="xdsl" type="static">
- - <hierarchy name="operational-data" type="static">
- - <hierarchy name="line" type="static">
- <hier-id name="if-index" is-named="no" type="Itf::XdslLineAndChannelItf::XdslLineAndChannel">1/1/4/1</hier-id>
- - <instance>
- <res-id name="if-index" short-name="if-index" type="Itf::XdslLineAndChannelItf::XdslLineAndChannel">1/1/4/1</res-id>
- <info name="adm-state" short-name="adm-state" type="Itf::ifAdminStatus">up</info>
- <info name="opr-state/tx-rate-ds" short-name="opr-state/tx-rate-ds" type="Xdsl::combinedCol">up :24252</info>
- <info name="tx-rate/us" short-name="tx-rate/us" type="Xdsl::bitrate">1189</info>
- <info name="tx-rate/ds" short-name="tx-rate/ds" type="Xdsl::bitrate">24252</info>
- <info name="cur-op-mode" short-name="cur-op-mode" type="Xdsl::OneOpModeTypeLinePreDef">g992-5-a</info>
- </instance>
- </hierarchy>
- </hierarchy>
- </hierarchy>
- </hierarchy>
- </runtime-data>
|
Voila le fichier XML qu je recupere. Mon soucis est que le nom des elements est compose, genre cur-op-mode. Du coup la variable n'est pas accepter quand je parse le document cf. mon code.
Code :
- <?php
- $dom = new DomDocument();
- $dom->load('line.xml');
- //$dom->save('line.xml');
- //$dom->validate();
- $line = $dom->getElementsByTagName('if-index');
- foreach($line as $if-index)
- echo $if-index->firstChild->nodeValue . "<br />";
- echo "---<br />";
- ?>
|
Ya t-il un moyen de pourvoir tout de meme utiliser ce nom de variable en la rendant valide par le parser? Car il m'est impossible de modify le format du fichier XML recu!
Ma source pour ce parse : http://eusebius.developpez.com/php5dom/
Merci d'avance.
Message édité par Stuntman le 29-06-2009 à 14:02:43