Witam,
Mam pewien problem z przechodzenie po drzewie xml, które przedstawiam poniżej,
<data>
<unit calendar="1">
<component id="1">
<history>
<tuple>
<value id="2">XXXXXXX</value>
<value id="4">XXXXXXX</value>
</tuple>
</history>
</component>
<component id="7">
<history>
<value id="7"/>
</history>
</component>
<component id="9">
<history>
<value id="9">XXXXXXX</value>
</history>
</component>
<component id="10">
<history>
<tuple>
<value id="11">XXXXXXX</value>
</tuple>
</history>
</component>
<component id="14">
<history>
<tuple>
<value id="15">XXXXXXX</value>
<value id="16">XXXXXXX</value>
<value id="17">XXXXXXX</value>
<value id="18">XXXXXXX</value>
<value id="19">XXXXXXX</value>
</tuple>
</history>
</component>
<component id="20">
<history>
<tuple>
<value id="21">XXXXXXX</value>
<value id="22">XXXXXXX</value>
<value id="23">XXXXXXX</value>
</tuple>
</history>
</component>
<component id="24">
<history>
<value id="24">XXXXXXX</value>
</history>
</component>
<component id="25">
<history>
<value id="25">XXXXXXX</value>
</history>
</component>
<component id="26">
<history>
<tuple>
<value id="27">XXXXXXX</value>
<value id="28">XXXXXXX</value>
<value id="29">XXXXXXX</value>
<value id="16">XXXXXXX</value>
<value id="30">XXXXXXX</value>
<value id="31">XXXXXXX</value>
<value id="32">XXXXXXX</value>
<value id="34">XXXXXXX</value>
<value id="35">XXXXXXX</value>
</tuple>
</history>
</component>
<component id="38">
<history>
<value id="38">XXXXXXX</value>
</history>
</component>
<component id="43">
<history>
<tuple begin="2006-04-01">
<value id="44">XXXXXXX</value>
<value id="45">XXXXXXX</value>
</tuple>
</history>
</component>
<component id="46">
<history>
<value id="46">XXXXXXX</value>
</history>
</component>
<component id="47">
<history>
<value id="47">XXXXXXX</value>
</history>
</component>
<component id="49">
<history>
<value id="49">XXXXXXX</value>
</history>
</component>
</unit>
<unit id="XXXX">
</unit>
Co potrzebuję uzyskać ?
Powyższe drzewo zawiera 'n' obiektów UNIT, a każdy z nich może zawierać do 49 elementów COMPONENT, a każdy z nich jeden lub kilka obiektów VALUE.
Potrzebuję przechodząc przez drzewo jednego obiektu UNIT wyświetlić wszystkie jego obiekty component wraz z wszystkimi obiektami VALUE w jednej lini.
Dobrze by było gdybym mógł ograniczyć się do wyświetlania dla np wszystkich UNIT pewnego zakresu obiektów COMPONENT (np id 7-9) wraz z wszystkimi obiektami VALUE.
Moje wypociny:
<?php
$dane_value = $xml -> xpath('/document/data/unit/component/history/tuple/value');
echo "<tr><td>Value 6</td><td>value 7</td><td>value 8</td><td>value 9</td></tr>"; foreach($dane_value as $val)
{
{
echo "<td>" . $val . "</td>"; } else {
}
}
?>
Problem jest jeszcze taki chciałbym aby linie mi się wyświetlały dla każdego UNIT oddzielnie, a otrzymuje jednym ciągiem wszystkie VALUE.
Probowałem ograniczyć linie wyświetlania do ostatniego VALUE w COMPONENCIE, ale nie w każdym UNIT występują COMPONET / VALUE o wszystkich id.
Mam nadzieje, że w miarę przystepny sposób napisałem o co mi chodzi.
Pozdrawiam