Vai al contenuto
ELECTRONICS ENGINEERINGelectronics-engineering.com
Archivio CORBA Python

IDL to XML (Through the WSDL File)

https://www.electronics-engineering.com/it/idl-to-xml-through-the-wsdl-file

Ti è stata utile questa pagina? Votala:
media 4,0 su 1 voto
IDL to XML (Through the WSDL File)

Questo articolo non è ancora disponibile in italiano: stai leggendo la versione originale (inglese). La traduzione italiana è in preparazione.

Archived article: written in 2017 and no longer updated. Some information, software or links may be out of date.

idl (interface description language) is the files that are defined the interface in corba. Often these files are organized with hierarchy libraries, so parsing the code and exporting this definition in a xml format can be really complex. However some tools are already available on internet to compile the idl and generate the file wsdl. 

The Web Services Description Language (WSDL) is an XML based interface definition language that is used for describing the functionality offered by a web service. The acronym is also used for any specific WSDL description of a web service (also referred to as a WSDL file), which provides a machine-readable description of how the service can be called, what parameters it expects, and what data structures it returns. Therefore, its purpose is roughly similar to that of a method signature in a programming language.

Here the link that contains the link to all the code to be installed in a PC with linux (https://metacpan.org/release/PERRAD/CORBA-XMLSchemas-2.62)

Wsdl file is a xml file without hierarchy where all needed information are located in one only file
after the creation of wsdl file, the python code attached below can be executed to parse the wsdl and create another xml with the requested output.

#############################################################
#------------------------------------------------------------
#   Copyright @ 2017 all right reserved
#   File Name:         |   Wsdltoxml.py
#   Unit Description   |   this python tool convert the wsdl
#                      |   to xml without scheme format (hardcoded)
#   Notes              |   this file can be executed from linux,
#                      |   cygwin or windows after the installation
#                      |   of the python SW
#                      |   with the command:
#                      |   python wsdltoxml.py 
#                      |   
#   Author             |   Graziano Nardelli
#   Revision           |   Vers 01
#------------------------------------------------------------
#############################################################



#import sys
#import xml.dom.minidom
from xml.dom.minidom import parseString

 
#open the xml file for reading:
#fileInput = open(sys.argv[1],'r')
fileInput = open('wsdl_files/XXX_R.wsdl','r')

#fileInput = open('XXXX_R.wsdl','r')

data = fileInput.read()
fileInput.close()

dom = parseString(data)


def isSimple(TypeF):
    simpleTypes = dom.getElementsByTagName('xs:simpleType')
    result = 0
    for simpleType in simpleTypes:
        if 'tns:' + simpleType.getAttribute('name') == TypeF:
            result = 1
    return result

    
    

def TakeChidsComplexType(TypeA,deep):
    global dom
    complexTypes = dom.getElementsByTagName('xs:complexType')
    #simpleTypes = dom.getElementsByTagName('xs:simpleType')
    for complexType in complexTypes:
        typeAsimps = TypeA.split(':')
        if len(typeAsimps) == 2:
            TypeAsimpl = typeAsimps[1]
            if (complexType.getAttribute('name') == TypeAsimpl):
                Sequences=complexType.childNodes
                for Sequence in Sequences:
                    Elementes = Sequence.getElementsByTagName('xs:element')
                    for Element in Elementes:
                        ElementNameAttribute = Element.getAttribute('name')
                        ElementTypeAttribute = Element.getAttribute('type')
                        if (ElementNameAttribute != '') and (ElementNameAttribute != 'item'):
                            blanc ='                               '
                            for i in range(deep):
                                blanc = '        ' + blanc
                            typeword = ElementTypeAttribute.partition(':')[2]
                            typeword2=typeword.split('.')
                            ElementTypeAttributeOnly2=typeword2[len(typeword2)-1]
                            Simp=isSimple(ElementTypeAttribute)
                            if Simp == 0:
                                if ElementTypeAttributeOnly2 == '':
                                    ElementTypeAttribute = Element.getElementsByTagName('xs:element')[0].getAttribute('type')
                                    typeword = ElementTypeAttribute.partition(':')[2]
                                    typeword2=typeword.split('.')
                                    ElementTypeAttributeOnly2=typeword2[len(typeword2)-1]
                                print blanc + '' 
                                deepplus = deep +1
                                TakeChidsComplexType(ElementTypeAttribute,deepplus)
                                print blanc + '' 
                            else:
                                print blanc + ''
                             

# EXECUTED
portType= dom.getElementsByTagName('portType')[0]
messages= dom.getElementsByTagName('message')
moduleInterface = portType.getAttribute('name').partition('.')
Module = moduleInterface[0]
Interface = moduleInterface[2]
print '\n        '
print '                '
Operation=portType.childNodes
for message in messages:
    NameMessage = message.getAttribute('name')
    FirstNameMessage = NameMessage.partition('.')[0]
    firstTime = 1
    firstTimeBack = 1
    if FirstNameMessage != '_exception':
        NameMessageOnly = NameMessage.partition('.')[2]
        NameMessageOnly2 = NameMessageOnly.partition('.')[2]
        Operations=message.childNodes
        print '                        '
        for Operation in Operations:
            NameAttribute = Operation.getAttribute('name')
            TypeAttribute = Operation.getAttribute('type')
            #if NameAttribute != 'mnMEIID' and NameAttribute != 'exception':
            if NameAttribute != 'exception':
                tword = TypeAttribute.partition(':')[2]
                tword2=tword.split('.')
                TypeAttributeOnly2=tword2[len(tword2)-1]
                print '                               '
                TakeChidsComplexType(TypeAttribute,1) 
                print '                               '
        print '                        '   
print '                \n        \n'

There are other method to convert idl to xml. This is another document that describe another kind of conversion

IDL-XML-CONVERTER A PACKAGE FOR TRANSFORMING IDL INTO XML

The IDL-XML-Converter-Package is used to convert IDL to XML files. Those XML files can then be used to write an appropriate OpenOffice-Registry

Iscriviti
Notificami
guest
0 commenti
Vecchi
Più recenti Le più votate
0
Esprimete la vostra opinione commentando.x