← Back to team overview

cdd-dev team mailing list archive

Re: [Branch ~cdd-dev/cdd/trunk] Rev 113: Added a first draft of a xmind to xsd converter.

 

Eduardo,

I had a chance to look at your xmind2xsd converter.   Thanks for
committing this effort.

Can you explain a bit about the process that is going on when it is
creating those XSDs?

BTW:  Yes, the comments and user messages do need to be in English.
:-)  Maybe we can get someone to translate them for you?

Thanks!

--Tim




On Mon, Mar 26, 2012 at 17:24,  <noreply@xxxxxxxxxxxxx> wrote:
> ------------------------------------------------------------
> revno: 113
> committer: Eduardo César
> branch nick: cdd
> timestamp: Mon 2012-03-26 19:23:19 -0300
> message:
>  Added a first draft of a xmind to xsd converter.
> added:
>  xmind2xsd.py
>
>
> --
> lp:cdd
> https://code.launchpad.net/~cdd-dev/cdd/trunk
>
> Your team CDD Developers is subscribed to branch lp:cdd.
> To unsubscribe from this branch go to https://code.launchpad.net/~cdd-dev/cdd/trunk/+edit-subscription
>
> === added file 'xmind2xsd.py'
> --- xmind2xsd.py        1970-01-01 00:00:00 +0000
> +++ xmind2xsd.py        2012-03-26 22:23:19 +0000
> @@ -0,0 +1,133 @@
> +# -*- coding: utf-8 -*-
> +
> +# This program is free software: you can redistribute it and/or modify
> +# it under the terms of the GNU General Public License as published by
> +# the Free Software Foundation, either version 3 of the License, or
> +# (at your option) any later version.
> +
> +# This program is distributed in the hope that it will be useful,
> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +# GNU General Public License for more details.
> +
> +# You should have received a copy of the GNU General Public License
> +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
> +
> +
> +# Eesse código aqui é só o primeiro rascunho de um conversor
> +# de xmind para xsd. Não tem quase comentários e os arquivos
> +# xsd gerados, apesar de válidos, são bem simples.
> +# E tem um funcionamento específico também, convertendo
> +# uma construção do xmind característica
> +
> +import sys
> +
> +print "xmind2xsd 0.1alpha"
> +print
> +
> +try:
> +    import mekk.xmind as xmind
> +except ImportError:
> +    print "Por favor, instale o pacote <mekk.xmind> e tente novamente."
> +    sys.exit(1)
> +
> +try:
> +    import lxml.etree as etree
> +    from lxml.builder import ElementMaker
> +except ImportError:
> +    print "Por favor, instale o pacote <lxml> e tente novamente."
> +    sys.exit(1)
> +
> +
> +
> +def checkparams():
> +    if len(sys.argv) < 2:
> +        print "Uso: xmind2xsd.py <arquivo xmind>"
> +        sys.exit(1)
> +
> +
> +
> +checkparams()
> +
> +emaker = ElementMaker(namespace='http://www.w3.org/2001/XMLSchema',
> +                      nsmap = {'xsd' : 'http://www.w3.org/2001/XMLSchema'})
> +
> +try:
> +    xmind_doc = xmind.XMindDocument.open(sys.argv[1])
> +except:
> +    print "Erro ao tentar abrir %s" % sys.argv[1]
> +    sys.exit(0)
> +
> +# Não gera xsd válido :s
> +def get_hierarchy(topic, xsd):
> +    myxsd = xsd
> +
> +    for fazer in (False, True): # attached and detached
> +        for t in topic.get_subtopics(detached=fazer):
> +            if t:
> +                if [i for i in t.get_subtopics()]: #Ugly, but works
> +                    tipo = 'complexType'
> +                else:
> +                    tipo = 'simpleType'
> +
> +                myxsd.append(emaker(tipo, {'name' : t.get_title().replace(' ','_')}))
> +                myxsd = myxsd.getchildren()[len(myxsd)-1]
> +
> +                get_hierarchy(t, myxsd)
> +
> +                myxsd = myxsd.getparent()
> +
> +xsd_doc = emaker('schema')
> +
> +
> +def get_attributes(topic, xsd):
> +    mydict = {}
> +    for t in topic.get_subtopics():
> +        tmp = [i for i in t.get_subtopics()]
> +        if tmp:
> +
> +            mydict[t.get_title()] = tmp[0].get_title()
> +
> +    return mydict
> +
> +def get_subtopics(topic, xsd):
> +    attributes = {}
> +    myxsd = xsd
> +    myxsd.append(emaker('sequence'))
> +    myxsd = myxsd.getchildren()[len(myxsd)-1]
> +    for t in topic.get_subtopics():
> +        attributes['name'] = t.get_title()
> +        attributes.update(get_attributes(t, myxsd))
> +        myxsd.append(emaker('element', attributes))
> +
> +    myxsd = myxsd.getparent()
> +
> +def get_topics(topic, xsd):
> +    myxsd = xsd
> +
> +    for t in topic.get_subtopics(detached=True):
> +        myxsd.append(emaker('complexType', {'name' : t.get_title().replace(' ','_')}))
> +        myxsd = myxsd.getchildren()[len(myxsd)-1]
> +        get_subtopics(t, myxsd)
> +        myxsd = myxsd.getparent()
> +
> +
> +print "Processando %s" % sys.argv[1]
> +print
> +
> +for sheet in xmind_doc.get_all_sheets():
> +    "Percorre cada sheet do arquivo .xmind"
> +
> +
> +    topic = sheet.get_root_topic()
> +
> +    namefile_xsd = topic.get_title().replace(' ', '_') + '.xsd'
> +
> +    get_topics(topic, xsd_doc)
> +
> +    print "Gerando arquivo %s ..." % namefile_xsd
> +    saida = etree.ElementTree(xsd_doc)
> +    saida.write(namefile_xsd, pretty_print=True, xml_declaration=True)
> +
> +print
> +print "Processamento concluído"
>
>
> _______________________________________________
> Mailing list: https://launchpad.net/~cdd-dev
> Post to     : cdd-dev@xxxxxxxxxxxxxxxxxxx
> Unsubscribe : https://launchpad.net/~cdd-dev
> More help   : https://help.launchpad.net/ListHelp
>



-- 
============================================
Timothy Cook, MSc           +1 713 254 3643
LinkedIn Profile:http://www.linkedin.com/in/timothywaynecook
Skype ID == timothy.cook
Academic.Edu Profile: http://uff.academia.edu/TimothyCook


Follow ups

References