Hallo,
ich habe folgende XML-Struktur:
Mir ist die ID des Spreads bekannt und ich möchte parallel dazu einen anderen Wert haben. Bisher habe ich das Ganze XML durchgeparst (foreach), die Position gemerkt und dann nochmal geparst. Mal abgesehen dass das nicht elegant ist, kommt es auch zu Fehlern, die ich mir nicht erklären kann. Deswegen hoffe ich auf einen Tipp, um das Ganze zu vereinfachen. Hier mein Ansatz:
Danke für Eure Hilfe.
Gruss
Dom
ich habe folgende XML-Struktur:
Code:
<?xml version="1.0" encoding="UTF-8"?> <publication Name="test" SpreadCount="3" RealLeadingPage="1" PageCount="4" FitTo="width" Browse="top"> <spread Id="ub6" LeadingPage="1" PageCount="1" Width="595.275590551" Height="841.889763778" Scale="1.0" > </spread> <spread Id="ubc" LeadingPage="2" PageCount="2" Width="1190.551181102" Height="841.889763778" Scale="1.0" > </spread> <spread Id="uc3" LeadingPage="4" PageCount="1" Width="595.275590551" Height="841.889763778" Scale="1.0" > </spread> </publication>
Code:
function getXMLAttrib ($doc, $tagPath, $tagPath2, $parallelValue) { $targets = new DOMXpath($doc); $targetDatas = $targets->query($tagPath); if (!is_null($targetDatas)) { foreach ($targetDatas as $targetData) { $nodes = $targetData->childNodes; foreach ($nodes as $counter => $node) { $value = $node->nodeValue; if ($value == $parallelValue) { $result = $counter; } } } $targetDatas2 = $targets->query($tagPath2); if (!is_null($targetDatas2)) { $result = array(); foreach ($targetDatas2 as $targetData2) { $nodes2 = $targetData2->childNodes; foreach ($nodes2 as $node2) { $value2 = $node2->nodeValue; $result[] = $value2; } } return $result[$counter]; } } }
Gruss
Dom
Comment