diff --git a/src/calibre/devices/prs505/sony_cache.py b/src/calibre/devices/prs505/sony_cache.py index 15245d3cd5..17eea3a27c 100644 --- a/src/calibre/devices/prs505/sony_cache.py +++ b/src/calibre/devices/prs505/sony_cache.py @@ -573,7 +573,10 @@ class XMLCache(object): ans = root.makeelement('{%s}text'%namespace, attrib=attrib, nsmap=root.nsmap) ans.tail = '\n' - root[-1].tail = '\n' + '\t' + if len(root) > 0: + root[-1].tail = '\n\t' + else: + root.text = '\n\t' root.append(ans) if thumbnail and thumbnail[-1]: ans.text = '\n' + '\t\t'