Carlos,

I don't actually have a fix or solution for this yet.  I'm still
working on it.

But, I do have a work-around that you can try.  What I've done is
copy the `parse` function that is near the bottom of a module
generated by gDS.  Then, when I call it, I pass in the missing name
space definitions.  (there are actually two that are missing: "pyld"
and "ei".)  Doing so generates an XML file that you can parse with
Lxml.

Take a look at `test01.py` (attached to a separate email).  You can
call it as follows:

    $ python test01.py test01.xml 
'xmlns:pyld="http://docs.oasis-open.org/ns/energyinterop/201110/payloads"; 
xmlns:ei="http://docs.oasis-open.org/ns/energyinterop/201110";'

You will need to change the import statement in `test01.py` so that
it refers to your module that was generated by `generateDS.py`.

Or, use the batch file `run-test.sh` (also attached to a separate
email).  If you are not on Linux, you will have to adapt it a bit.

Hope this helps at least temporarily.  And, I'll keep looking for a
fix that does not require you to use the kludge described above.

By the way, I'm not sure that I'm working with the same oadr schema
that you are using.  But, since I was able to produce an error that
seems to be the same as the one you've reported, it seems good
enough.

Dave

On Sun, Jun 09, 2019 at 11:27:21AM +0100, Carlos AG wrote:
> Hi,
> 
> I am not sure where is the best place to ask this question about using a
> file I created with generateDS. If this is not the right place,
> apologies and I would appreciate to be told where to post it.
> 
> I am having the following problem: when I generate the xml using the
> export function, the children elements are missing the namespace.
> 
> I have been using a file created with Python 2.7.14 and GenerateDS
> 2.29.6 and everything was working well, this was my exported xml:
> 
> >  <oadr:oadrSignedObject xmlns:oadr="http://openadr.org/oadr-2.0b/2012/07";>
> >         <oadr:oadrCreatedEvent
> > xmlns:oadr="http://openadr.org/oadr-2.0b/2012/07";
> > xmlns:pyld="http://docs.oasis-open.org/ns/energyinterop/201110/payloads"; >
> >             <pyld:eiCreatedEvent
> > xmlns:oadr="http://openadr.org/oadr-2.0b/2012/07";
> > xmlns:ei="http://docs.oasis-open.org/ns/energyinterop/201110" 
> > xmlns:pyld="http://docs.oasis-open.org/ns/energyinterop/201110/payloads";>
> >                 <ei:eiResponse
> > xmlns:oadr="http://openadr.org/oadr-2.0b/2012/07";
> > xmlns:ei="http://docs.oasis-open.org/ns/energyinterop/201110" 
> > xmlns:pyld="http://docs.oasis-open.org/ns/energyinterop/201110/payloads"; >
> >                     <ei:responseCode>200</ei:responseCode>
> >                 </ei:eiResponse>
> >                 <ei:eventResponses
> > xmlns:oadr="http://openadr.org/oadr-2.0b/2012/07";
> > xmlns:ei="http://docs.oasis-open.org/ns/energyinterop/201110";>
> >                     <ei:eventResponse
> > xmlns:oadr="http://openadr.org/oadr-2.0b/2012/07";
> > xmlns:ei="http://docs.oasis-open.org/ns/energyinterop/201110" 
> > xmlns:pyld="http://docs.oasis-open.org/ns/energyinterop/201110/payloads"; >
> >                         <ei:responseCode>200</ei:responseCode>
> >                         <pyld:requestID>300</pyld:requestID>
> >                         <ei:qualifiedEventID
> > xmlns:oadr="http://openadr.org/oadr-2.0b/2012/07";
> > xmlns:ei="http://docs.oasis-open.org/ns/energyinterop/201110"; >
> >                             <ei:eventID>4</ei:eventID>
> >                            
> > <ei:modificationNumber>0</ei:modificationNumber>
> >                         </ei:qualifiedEventID>
> >                         <ei:optType>none</ei:optType>
> >                     </ei:eventResponse>
> >                 </ei:eventResponses>
> >                 <ei:venID>1</ei:venID>
> >             </pyld:eiCreatedEvent>
> >         </oadr:oadrCreatedEvent>
> >     </oadr:oadrSignedObject>
> 
> 
> But I have recently generated a new file with python 3.7 and generateDS
> 2.32.0. This is the xml (note the missing namespaces in the children
> element)
> 
> > <oadrSignedObject xmlns:oadr="http://openadr.org/oadr-2.0b/2012/07";>
> >         <oadr:oadrCreatedEvent>
> >             <pyld:eiCreatedEvent>
> >                 <ei:eiResponse>
> >                     <responseCode>200</responseCode>
> >                 </ei:eiResponse>
> >                 <ei:eventResponses>
> >                     <eventResponse>
> >                         <responseCode>200</responseCode>
> >                         <requestID>300</requestID>
> >                         <ei:qualifiedEventID>
> >                             <eventID>4</eventID>
> >                             <modificationNumber>0</modificationNumber>
> >                         </ei:qualifiedEventID>
> >                         <optType>none</optType>
> >                     </eventResponse>
> >                 </ei:eventResponses>
> >                 <venID>1</venID>
> >             </pyld:eiCreatedEvent>
> >         </oadr:oadrCreatedEvent>
> >     </oadrSignedObject>
> 
> 
> When trying to *etree_.fromstring* the oadrSignedObject I get the error:
> "Namespace prefix pyld on eiCreatedEvent is not defined"
> 
> After digging in the generateDS files I can see that the problem is in
> the *exportChildren()* methods and how they call the export methods of
> the children elements:
> 
>   * In the old file:
> 
>         self.oadrCreatedEvent.export(outfile, level, namespace_='oadr:',
>         name_='oadrCreatedEvent', pretty_print=pretty_print)
> 
>   * In the new file:
> 
>         self.oadrCreatedEvent.export(outfile, level,
>         *namespaceprefix_='oadr:', namespacedef_=''*,
>         name_='oadrCreatedEvent', pretty_print=pretty_print)
> 
> In the new file we are passing *namespaceprefix_ *and *namespacedef_*
> which overwrite the default ones used in the child's export method, if
> they were not passed everything would work well.
> 
> The only thing I have tried to do to sort the problem was to create my
> file again using the *--no-namespace-defs* but what that does is the no
> name space is added at all.
> 
> Does anybody know what should I do to get the namespace in the child
> elements.
> 
> Thank you very much in advance.
> 
>    Carlos
> 
> **
> -- 
> 
> Carlos Alonso-Gabizon - Carbon Co-op - Technical Developer
> 
> m: 07990 725 966
> 
> e: car...@carbon.coop
> w: https://carbon.coop
> t: @carboncoop
> 
> People Powered Not Fossil Fuelled: an intro to Carbon Co-op:
> http://www.carbon.coop/reports/CarbonCoopPeoplePoweredBooklet.pdf
> 
> Office: c/o URBED, 10 Little Lever Street, Manchester M1 1HR
> 
> Society for the Reduction of Carbon Ltd (Trading as Carbon Co-op)
> Registered address: Holyoake House, Hanover Street, Manchester M60 0AS United 
> Kingdom
> Registered under the Industrial and Provident Societies Act 1965 
> Registration Number 31342R
> 


> _______________________________________________
> generateds-users mailing list
> generateds-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/generateds-users


-- 

Dave Kuhlman
http://www.davekuhlman.org


_______________________________________________
generateds-users mailing list
generateds-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/generateds-users

Reply via email to