Raúl,

Thank you for sending that schema and your test code.  That helped
me understand what's happening.

One thing we need to understand is that the elements inside of a
`calibration_parameters`/`calibration_parametersSub` (specifically
`cm_mm01`, `co_mm01`, `cm_mm02`, etc) are each a `xsd:complexType`.
They contain floats, but they are not floats themselves.  They need
to be instances of Python classes.  And actually, since they are
each defined with `maxOccurs` greater than 1, they each contain an
array of floats.  So, you can either (1) create them with a Python
list or (2) create them and then use the `add_xxx` methods to add
individual floats.

And then, your schema requires more nesting than what we originally
created.  We need the following nesting:

    <commands>
        <tc>
            <change_adcs_calibration_parameters due_time="10">
                <calibration_parameters>
                    <mm_working>
                        <mgm1>1.</mgm1>
                        ...
                    </mm_working>
                    <cm_mm01>
                    ...
                    </cm_mm01>
                    <co_mm01>
                        <offset>1.2</offset>
                        ...

Oh, and, in order to get it to validate, each calibration matrix
needs exactly 9 values and each offset matrix needs to contain
exactly 3 offsets.  That's because, for example, of the following:

    minOccurs="9" maxOccurs="9"

in the definition of `calibration_matrix`.

Whew!  It's a little tricky.  But, if we did not want it to be
tricky and complicated, I suppose we probably wouldn't be using XML.
Sigh.  Actually, I suspect that what you *do* with this data is even
a lot more complex, yet.

I've attached a python script that is a modification of the script
that you sent me.  It reflects the changes suggested above.

I used the following to generate output:

    $ ./test04.py output.xml

If you have `xmllint` installed on your machine, you can use the
following to validate your output:

    $ xmllint --noout --schema tc-schema.xsd output.xml

I hope this helps.  And, hope your project goes well.

Let me know if and when you have more questions.

Dave

On Mon, Apr 29, 2019 at 11:53:55PM +0200, Raúl Torres García wrote:
> Hi Dave!
> 
> Thank you so much for answering me!
> 
> I send you in this email the XML schema and the code that I put on my
> Python Interpreter in order to get the XML file.
> The version is: "Generated Wed Mar 20 09:18:27 2019 by generateDS.py
> version 2.30.11."
> When I reproduced the code I wrote this: "generateDS.py -o "TC_api.py" -s
> "tc_sub.py" --super="TC_api" tc-schema.xsd"
> 
> My proposal is to build a Python object and export it to a python file. I
> am going to show you how I get the error:
> The next orders are given in a Python Interpreter:
> 
> >> import tc_sub
> >> commads = tc_sub.commandsSub()
> >> due_time = 10
> >> tc = tc_sub.change_adcs_calibration_parametersSub(due_time)
> >> mgm1 = 1.0
> >> mgm2 = 0.0
> >> mgm3 = -1.0
> >> working_mgm = tc_sub.working_mgmSub()
> >> working_mgm.set_mgm1(mgm1)
> >> working_mgm.set_mgm2(mgm2)
> >> working_mgm.set_mgm3(mgm3)
> >> cm_mm01 = 1.1
> >> co_mm01 = 1.2
> >> cm_mm02 = 2.1
> >> co_mm02 = 2.2
> >> cm_mm03 = 3.1
> >> co_mm03 = 3.2
> >> calibration_parameters = tc_sub.calibration_parametersSub()
> >> calibration_parameters.set_mm_working(working_mgm)
> >> calibration_parameters.set_cm_mm01(cm_mm01)
> >> calibration_parameters.set_co_mm01(co_mm01)
> >> calibration_parameters.set_cm_mm02(cm_mm02)
> >> calibration_parameters.set_co_mm02(co_mm02)
> >> calibration_parameters.set_cm_mm03(cm_mm03)
> >> calibration_parameters.set_co_mm03(co_mm03)
> >> tc.set_calibration_parameters(calibration_parameters)
> >> commands.add_tc(tc)
> 
> Here, I export to a XML file
> 
> >> file = open("TC.xml", "w")
> >> file.write("<?xml version=\"1.0\"?>" +'\n')
> >> self.export(file,0)
> >> file.close()
> 
> And that's all, with this code in Python I got the error which I send you
> in the last mail.
> 
> Thank you so much Dave! It's important to solve this problem in order to
> continue with my final degree!
> Best regards!
> 
> El lun., 29 abr. 2019 a las 22:26, Dave Kuhlman (<dkuhl...@davekuhlman.org>)
> escribió:
> 
> > Raúl,
> >
> > Thank you for reporting this.
> >
> > Looks like a bug in the way that generateDS is generating your code.
> > I'll take a look.
> >
> > I tried to reproduce the error that you report, but I could not.  It
> > must be a special or corner case of some kind.
> >
> > Would it be possible to send me a copy of your XML schema.  Then I
> > could generate a module, and reproduce your exception.  Also, it
> > would help me if I had an XML instance document that, when parsed
> > and exported, produces this exception.
> >
> > Question -- What version of generateDS are you using.  The version
> > number should be in a comment near the top of the module that you
> > generated.
> >
> > Thanks for your help.
> >
> > Dave
> >
> > On Mon, Apr 29, 2019 at 11:53:06AM +0200, Raúl Torres García wrote:
> > > Hello Dave!
> > >
> > > I am Raul, an University Student from Madrid. I am doing my final degree
> > > project and I am using your library GenerateDS.
> > > I am writing to you to ask you a doubt. I have generated the python code
> > > with my XML schema and I am trying to export some python data to a xml
> > file.
> > > When I execute my code, I get the next error:
> > > "
> > > Traceback (most recent call last):
> > >   File "telecomandos.py", line 4, in <module>
> > >     telecomandos = commands.sendTCs()
> > >   File "/home/rtorres/TFG/pruebaxml_29Abril_error/tc_sub.py", line 340,
> > in
> > > sendTCs
> > >     self.export(file,0)
> > >   File "/home/rtorres/TFG/pruebaxml_29Abril_error/TC_api.py", line 867,
> > in
> > > export
> > >     self.exportChildren(outfile, level + 1, namespaceprefix_,
> > > namespacedef_, name_='commands', pretty_print=pretty_print)
> > >   File "/home/rtorres/TFG/pruebaxml_29Abril_error/TC_api.py", line 880,
> > in
> > > exportChildren
> > >     tc_.export(outfile, level, namespaceprefix_, namespacedef_='',
> > > name_='tc', pretty_print=pretty_print)
> > >   File "/home/rtorres/TFG/pruebaxml_29Abril_error/TC_api.py", line 998,
> > in
> > > export
> > >     self.exportChildren(outfile, level + 1, namespaceprefix_,
> > > namespacedef_, name_='tc', pretty_print=pretty_print)
> > >   File "/home/rtorres/TFG/pruebaxml_29Abril_error/TC_api.py", line 1023,
> > in
> > > exportChildren
> > >     self.change_adcs_calibration_parameters.export(outfile, level,
> > > namespaceprefix_, namespacedef_='',
> > > name_='change_adcs_calibration_parameters', pretty_print=pretty_print)
> > >   File "/home/rtorres/TFG/pruebaxml_29Abril_error/TC_api.py", line 1815,
> > in
> > > export
> > >     self.exportChildren(outfile, level + 1, namespaceprefix_,
> > > namespacedef_, name_='change_adcs_calibration_parameters',
> > > pretty_print=pretty_print)
> > >   File "/home/rtorres/TFG/pruebaxml_29Abril_error/TC_api.py", line 1829,
> > in
> > > exportChildren
> > >     self.calibration_parameters.export(outfile, level, namespaceprefix_,
> > > namespacedef_='', name_='calibration_parameters',
> > pretty_print=pretty_print)
> > >   File "/home/rtorres/TFG/pruebaxml_29Abril_error/TC_api.py", line 3061,
> > in
> > > export
> > >     self.exportChildren(outfile, level + 1, namespaceprefix_,
> > > namespacedef_, name_='calibration_parameters', pretty_print=pretty_print)
> > >   File "/home/rtorres/TFG/pruebaxml_29Abril_error/TC_api.py", line 3076,
> > in
> > > exportChildren
> > >     self.cm_mm01.export(outfile, level, namespaceprefix_,
> > namespacedef_='',
> > > name_='cm_mm01', pretty_print=pretty_print)
> > > AttributeError: 'float' object has no attribute 'export'
> > > "
> > > I don't know how to solve this AttributeError. The data which I am using
> > in
> > > the python code is Float type, so I don't know what is wrong. Could you
> > > help me?
> > >
> > > Thank you so much for your time and sorry for the inconvenience!
> > > Best regards!
> > > --
> > > Raúl Torres García
> >
> > --
> >
> > Dave Kuhlman
> > http://www.davekuhlman.org
> >
> 
> 
> -- 
> Raúl Torres García



-- 

Dave Kuhlman
http://www.davekuhlman.org
#!/usr/bin/env python

import sys
import os
import tc_sub


def open_output_file(outfilename):
    if os.path.exists(outfilename):
        msg = 'output file {} exists.  overwrite? (y/n): '.format(
            outfilename)
        reply = input(msg)
        if reply == 'n':
            sys.exit()
    outfile = open(outfilename, "w")
    return outfile


def create_commands():
    commands = tc_sub.commandsSub()
    tc = tc_sub.tcSub()
    due_time = 10
    change_adcs_cp = tc_sub.change_adcs_calibration_parametersSub(
        due_time=due_time)
    calibration_parameters = tc_sub.calibration_parametersSub()
    mgm1 = 1.0
    mgm2 = 0.0
    mgm3 = -1.0
    working_mgm = tc_sub.working_mgmSub()
    working_mgm.set_mgm1(mgm1)
    working_mgm.set_mgm2(mgm2)
    working_mgm.set_mgm3(mgm3)
    cm_mm01 = tc_sub.calibration_matrixSub(
        value=[1.1, 1.1, 1.1, 1.1, 1.1, 1.1, 1.1, 1.1, 1.1])
    co_mm01 = tc_sub.offset_matrixSub(
        offset=[1.2, 1.2, 1.2])
    cm_mm02 = tc_sub.calibration_matrixSub(
        value=[2.1, 2.1, 2.1, 2.1, 2.1, 2.1, 2.1, 2.1, 2.1])
    co_mm02 = tc_sub.offset_matrixSub(
        offset=[2.2, 2.2, 2.2])
    cm_mm03 = tc_sub.calibration_matrixSub(
        value=[3.1, 3.1, 3.1, 3.1, 3.1, 3.1, 3.1, 3.1, 3.1])
    co_mm03 = tc_sub.offset_matrixSub(
        offset=[3.2, 3.2, 3.2])
    calibration_parameters.set_mm_working(working_mgm)
    calibration_parameters.set_cm_mm01(cm_mm01)
    calibration_parameters.set_co_mm01(co_mm01)
    calibration_parameters.set_cm_mm02(cm_mm02)
    calibration_parameters.set_co_mm02(co_mm02)
    calibration_parameters.set_cm_mm03(cm_mm03)
    calibration_parameters.set_co_mm03(co_mm03)
    change_adcs_cp.set_calibration_parameters(calibration_parameters)
    tc.set_change_adcs_calibration_parameters(change_adcs_cp)
    commands.add_tc(tc)
    return commands


def create_and_generate(outfilename):
    commands = create_commands()
    outfile = open_output_file(outfilename)
    outfile.write("<?xml version=\"1.0\"?>" + '\n')
    commands.export(outfile, 0)
    outfile.close()


def main():
    args = sys.argv[1:]
    if len(args) != 1:
        sys.exit("usage: python test01.py <outfile.xml>")
    outfilename = args[0]
    create_and_generate(outfilename)


if __name__ == '__main__':
    main()
<?xml version="1.0"?>
<commands>
    <tc>
        <change_adcs_calibration_parameters due_time="10">
            <calibration_parameters>
                <mm_working>
                    <mgm1>1.</mgm1>
                    <mgm2>0.</mgm2>
                    <mgm3>-1.</mgm3>
                </mm_working>
                <cm_mm01>
                    <value>1.1</value>
                    <value>1.1</value>
                    <value>1.1</value>
                    <value>1.1</value>
                    <value>1.1</value>
                    <value>1.1</value>
                    <value>1.1</value>
                    <value>1.1</value>
                    <value>1.1</value>
                </cm_mm01>
                <co_mm01>
                    <offset>1.2</offset>
                    <offset>1.2</offset>
                    <offset>1.2</offset>
                </co_mm01>
                <cm_mm02>
                    <value>2.1</value>
                    <value>2.1</value>
                    <value>2.1</value>
                    <value>2.1</value>
                    <value>2.1</value>
                    <value>2.1</value>
                    <value>2.1</value>
                    <value>2.1</value>
                    <value>2.1</value>
                </cm_mm02>
                <co_mm02>
                    <offset>2.2</offset>
                    <offset>2.2</offset>
                    <offset>2.2</offset>
                </co_mm02>
                <cm_mm03>
                    <value>3.1</value>
                    <value>3.1</value>
                    <value>3.1</value>
                    <value>3.1</value>
                    <value>3.1</value>
                    <value>3.1</value>
                    <value>3.1</value>
                    <value>3.1</value>
                    <value>3.1</value>
                </cm_mm03>
                <co_mm03>
                    <offset>3.2</offset>
                    <offset>3.2</offset>
                    <offset>3.2</offset>
                </co_mm03>
            </calibration_parameters>
        </change_adcs_calibration_parameters>
    </tc>
</commands>
_______________________________________________
generateds-users mailing list
generateds-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/generateds-users

Reply via email to