How to use the nml.NeurokernelDoc function in nml

To help you get started, we’ve selected a few nml examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github neurokernel / neurokernel / neurokernel / neuroml / utils.py View on Github external
def write(nk_doc, file, root_name='nk'):
    """
    Write a Neurokernel NeuroML document to an XML file.

    Parameters
    ----------
    nk_doc : neurokernel.neuroml.NeurokernelDoc
        Neurokernel NeuroML document root object.
    file : str or file
        Output file name or handle.
    root_name : str
        Document root name.
    """

    assert isinstance(nk_doc, NeurokernelDoc)

    ns_def = 'xmlns="http://www.neuroml.org/schema/neuroml2"\n'
    ns_def += '    xmlns:xs="http://www.w3.org/2001/XMLSchema"\n'
    ns_def += '    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\n'
    ns_def += '    xsi:schemaLocation="http://www.neuroml.org/schema/neuroml2'
    ns_def += ' https://raw.github.com/neurokernel/neurokernel/development/neuroml/neurokernel.xsd"'

    # Set name_ param to ensure root element named correctly due to generateDS
    # limitation:
    try:
        nk_doc.export(file, 0, name_=root_name,
                      namespacedef_=ns_def) 
    except:
        try:
            with open(file, 'w') as f:
                nk_doc.export(f, 0, name_=root_name,