Skip to content

Instantly share code, notes, and snippets.

@mikaelz
Last active August 29, 2015 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikaelz/288d1611eec0f80c1293 to your computer and use it in GitHub Desktop.
Save mikaelz/288d1611eec0f80c1293 to your computer and use it in GitHub Desktop.
Parse Pohoda categories XML. The XML contains nested namespaces. Reused code from https://webtrh.cz/120959-parsovani-vnorenych-zaznamu-xml?p=616757#post616757 Alternative parsing can be found at https://gist.github.com/lynt-smitka/6a50bdf97bb32a64e34b
$xml = file_get_contents($_FILES['xml']['tmp_name']);
$xml = simplexml_load_string($xml);
$ns = $xml->getNameSpaces(true);
foreach ($xml->xpath('//lst:categoryDetail') as $categories) {
$ctg = $categories->children($ns['ctg']);
foreach ($ctg->category as $category) {
insert_page($category->id, $category->name, 0);
if (isset($category->subCategories)) {
insertSubcategory($category);
}
}
}
function insertSubcategory($category) {
foreach ($category->subCategories->category as $subcategory) {
insert_page($subcategory->id, $subcategory->name, $category->id);
if (isset($subcategory->subCategories)) {
insertSubcategory($subcategory);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment