Hi All ! Current Situation :
I'm trying to parse a DomDocument with XPath, the result should be an array with Categories and Subcategories .
The problem is, the person that made the HTML did not structure the info with the subcategories in the main categories, they are just delimited by pure css .
THe html loos like this :
<div class="menu_item">Main Category AC</div>
<div class="submenu_div">
<a href="http://www.link.com/313">
<div class="sub_item">
<h3>Sub Categ A</h3>
</div>
</a>
<a href="http://www.link.com/475">
<div class="sub_item">
<h3>Sub Categ B</h3>
</div>
</a>
<a href="http://www.link.com/321">
<div class="sub_item">
<h3>Sub Categ C</h3>
</div>
</a>
</div>
<div class="menu_item">Main Category BC</div>
<div class="submenu_div">
<a href="http://www.link.com/313">
<div class="sub_item">
<h3>Sub Categ X</h3>
</div>
</a>
<a href="http://www.link.com/475">
<div class="sub_item">
<h3>Sub Categ Y</h3>
</div>
</a>
<a href="http://www.link.com/321">
<div class="sub_item">
<h3>Sub Categ Z</h3>
</div>
</a>
</div>
Now, with this php I can extract de categories and subcategories, but it's just a list, I don't know what subcategory is in what category, and I'm stuck .
How can I use Xpath to do extract the main category subcategories and assign a parent to every subcategory ?
$doc = new DomDocument;
@$doc->loadHTML($html);
$xpath = new DOMXPath($doc);
foreach( $xpath->query('//div[@class="menu_item"]|//div[@class="submenu_div"]/a/div/h3') as $e ) {
echo $e->nodeValue, "<br />\n";
}