From 65c82679802631525d7503b51bab31b568b883f4 Mon Sep 17 00:00:00 2001
From: Andrew Dolgov <fox@madoka.volgo-balt.ru>
Date: Wed, 15 Aug 2012 15:55:41 +0400
Subject: [PATCH] opml: clean empty categories

---
 classes/opml.php | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/classes/opml.php b/classes/opml.php
index f7bab4fff..011c66eb2 100644
--- a/classes/opml.php
+++ b/classes/opml.php
@@ -201,6 +201,16 @@ class Opml extends Protected_Handler {
 		$doc->formatOutput = true;
 		$doc->preserveWhiteSpace = false;
 		$doc->loadXML($out);
+
+		$xpath = new DOMXpath($doc);
+		$outlines = $xpath->query("//outline[@title]");
+
+		// cleanup empty categories
+		foreach ($outlines as $node) {
+			if ($node->getElementsByTagName('outline')->length == 0)
+				$node->parentNode->removeChild($node);
+		}
+
 		$res = $doc->saveXML();
 
 		// saveXML uses a two-space indent.  Change to tabs.