Re: [Generateds-discuss] Single simpleType results in un-exportable enum
Brought to you by:
dkuhlman
From: Dave K. <dku...@da...> - 2023-06-19 22:05:29
|
David, Good to hear from you. Sorry I'm a bit slow responding. Here are a few words of explanation, or maybe excuse making, depending on your point of view: One, `generateds` is designed around the idea that we want to generate Python classes that help us process the elements in a XML instance document. It generates each of those Python classes from an `xs:complexType` definition in the XML schema. But, your schema does not have any complex type definitions. And, therefore, we do not get code that is of much use. Two, the XML instance document that you included does not validate against your schema. You can use `xmllint` to check this. Or, if you do not have `xmllint`, you can use `validate.py`, which is in `generateds/utils/validate.py` in the generateds source repo: `https://sourceforge.net/projects/generateds/` and `https://sourceforge.net/p/generateds/code/ci/default/tree/`. If you have Mercurial (Hg), you can download it with this: `hg clone http://hg.code.sf.net/p/generateds/code generateds-code`. `test01.xsd` and `test01-01.xml` (attached) contain your schema and instance doc (ightly patched). When I run `xmllint`, I see the following: $ xmllint --noout --schema test01.xsd test01-01.xml test01-01.xml:1: element MyTestXML: Schemas validity error : Element 'MyTestXML': No matching global declaration available for the validation root. test01-01.xml fails to validate `validate.py` produces a similar message because it is built on top of `lxml` which is built on top of `libxml2` (and `libxml2-utils`, which provides `xmllint`). So, my suggestion is to add a complex type. `test02.xsd` and `test02-01.xml` (attached) contain a schema and instance doc with a `complexType` that uses your `simpleType`. The files `test02.xsd` and `test02-01.xml` (attached) provide an XML schema and an XML instance doc that does this. Maybe it will give you a hint about how to address your needs. Hope this helps. If you have more questions, please let me know. Dave Quoting David Ferguson <fer...@gm...>: > Hi, > > I'm trying to use generateDS to parse and generate XML documents, and > am very impressed so far - it is handling some complex XSDs very well. > > However I seem to have run into an issue for a simple XSD, where only > a single simpleType enum is defined. My XDS is as follows: > > <?xml version="1.0" encoding="UTF-8" standalone="no"?> > <xsi:schema xmlns:xsi="http://www.w3.org/2001/XMLSchema" > xmlns:xsd="http://www.w3.org/2001/XMLSchema" version="4.1.0"> > <xsi:simpleType name="MyTestXML"> > <xsi:restriction base="xsd:string"> > <xsi:enumeration value="ValueA"/> > <xsi:enumeration value="ValueB"/> > </xsi:restriction> > </xsi:simpleType> > </xsi:schema> > > And the XML documents are very simple, for example > <MyTestXML>ValueA</MyTestXML>. > > When I run generateDS with `generateDS -o test.py test.xsd `, the > output is just an enum, eg: > > class MyTestXML(str, Enum): > VALUE_A='ValueA' > VALUE_B='ValueB' > > And therefore I cannot parse, or export XML documents. Is this > something I'm doing wrong, or a limitation in the program? > > Many thanks, > David > > > _______________________________________________ > Generateds-discuss mailing list > Gen...@li... > https://lists.sourceforge.net/lists/listinfo/generateds-discuss -- Dave Kuhlman http://www.davekuhlman.org |