I'm trying to filter out each XML category string of a specific category. How would I get this working?
For example I just want the x elements from the category Category1.
Example XML:
<store id="1" name="store">
<species name="stud">
<Category1 name="Category1">
<x category="Hairs" id="20098288"/>
<x category="Hairs" id="20098289"/>
</Category1>
<Category2 name="Category2">
<x category="Shirts" id="24342342"/>
<x category="Shirts" id="24342342"/>
</Category2>
<Category3 name="Category3">
<x category="Jackets" id="423423423"/>
<x category="Jackets" id="423423423"/>
</Category3>
</species>
</store>
My actual code, which would let me access every category's child elements:
<?php
foreach($xmlDocument->species as $species_elem){
foreach($species_elem->attributes() as $child){
foreach ($child->x as $item){
$itemID = $item->attributes()->id;
}
}
}
?>
But I want to specify a Category which only should be access able. For example
$category = 'Category1';
Pseudo code:
<?php
foreach($species as $species_elem){
foreach($species_elem which contains $Category1 as $category){
foreach ($child->x as $item){
$itemID = $item->attributes()->id;
}
}
}
?>