diff --git a/README.md b/README.md index 029b622..7571908 100644 --- a/README.md +++ b/README.md @@ -4,13 +4,7 @@ ##Install XMind SDK for python -Clone the repository to a local working directory - - git clone https://github.com/xmindltd/xmind-sdk-python.git - -Now there will be a directory named `xmind-sdk-python` under the current directory. Change to the directory `xmind-sdk-python` and install **XMind SDK for python**. - - python setup.py install + pip install git+https://github.com/xmindltd/xmind-sdk-python.git *It is highly recommended to install __XMind SDK for python__ under an isolated python environment using [virtualenv](https://pypi.python.org/pypi/virtualenv)* diff --git a/examples/dump.py b/examples/dump.py new file mode 100644 index 0000000..0186317 --- /dev/null +++ b/examples/dump.py @@ -0,0 +1,42 @@ +#! /usr/bin/env python +# -*- coding: utf-8 -*- +# +# Author: hzsunshx +# Created: 2014-11-14 11:27 + +""" +dump xmind files +""" + +import xmind +import pipes + +M = {} + +def _echo(tag, element, indent=0): + title = element.getTitle() + M[element.getID()] = title + print '\t'*indent, tag, ':', pipes.quote(title) + +def dump_sheet(sheet): + rootTopic = sheet.getRootTopic() + _echo('RootTopic', rootTopic, 1) + + for topic in rootTopic.getSubTopics() or []: + _echo('AttachedSubTopic', topic, 2) + + for topic in rootTopic.getSubTopics(xmind.core.const.TOPIC_DETACHED) or []: + _echo('DetachedSubTopic', topic, 2) + + for rel in sheet.getRelationships(): + id1, id2 = rel.getEnd1ID(), rel.getEnd2ID() + print 'Relation: [%s] --> [%s]' % (M.get(id1), M.get(id2)) + +def main(): + x = xmind.load('test2.xmind') + for sheet in x.getSheets(): + _echo('Sheet', sheet) + dump_sheet(sheet) + +if __name__ == '__main__': + main() diff --git a/example.py b/examples/example.py similarity index 100% rename from example.py rename to examples/example.py diff --git a/examples/test2.xmind b/examples/test2.xmind new file mode 100644 index 0000000..c6d2f2a Binary files /dev/null and b/examples/test2.xmind differ diff --git a/xmind/core/const.py b/xmind/core/const.py index a9b27d1..e637c01 100644 --- a/xmind/core/const.py +++ b/xmind/core/const.py @@ -67,6 +67,7 @@ TOPIC_ROOT = "root" TOPIC_ATTACHED = "attached" +TOPIC_DETACHED = "detached" FILE_PROTOCOL = "file://" TOPIC_PROTOCOL = "xmind:#" diff --git a/xmind/core/sheet.py b/xmind/core/sheet.py index b042e40..1acc2bf 100644 --- a/xmind/core/sheet.py +++ b/xmind/core/sheet.py @@ -64,6 +64,13 @@ def createRelationship(self, end1, end2, title=None): return rel + def getRelationships(self): + """ + Get relationships from current sheet + """ + elems = RelationshipsElement(self._getRelationships()) + return map(RelationshipElement, elems.iterChildNodesByTagName(const.TAG_RELATIONSHIP)) + def _getRelationships(self): return self.getFirstChildNodeByTagName(const.TAG_RELATIONSHIPS)