Hi all– I’m trying to diff a few thousand xsd files and was excited to try [xsData toolkit](https://xsdata.readthedocs.io/en/latest/) to see if diffing pre-db dataclass files would be easier than diffing parsed/stored xsd’s.
Everything was going great…until i realized xsData is only processing complexTypes and not simpleTypes. My MRE & config is posted below, but I’m thinking that I should first ask:
Does xsdata require some type of external extension in order to process simpleTypes?
Am i missing something basic about the limitations of parsing simpleTypes? It’s also possible that i’m not configured correctly for base type restrictions?
I’m struggling with xsdata’s docs. They offer little in terms of config options, use cases, etc, so it’s hard for me to gauge whether or not this will require a config tag, plugin, or custom parser. I’ve found few/no workable answers on stackoverflow.
.xsdata.xml for reference:
<?<?xml version="1.0" encoding="UTF-8"?> <Config xmlns="http://pypi.org/project/xsdata" version="24.11"> <Output maxLineLength="320" genericCollections="false" unionType="false"> <Format repr="true" eq="true" order="false" unsafeHash="false" frozen="false" slots="false" kwOnly="false">dataclasses</Format> <PostponedAnnotations>false</PostponedAnnotations> <Structure>filenames</Structure> <DocstringStyle>Accessible</DocstringStyle> <RelativeImports>false</RelativeImports> <CompoundFields defaultName="values" useSubstitutionGroups="false" forceDefaultName="false" maxNameParts="3">true</CompoundFields> <WrapperFields>true</WrapperFields> <UnnestClasses>true</UnnestClasses> <IgnorePatterns>false</IgnorePatterns> <IncludeHeader>false</IncludeHeader> </Output> <Conventions> <ClassName case="originalCase" safePrefix="type"/> <FieldName case="originalCase" safePrefix="value"/> <ConstantName case="originalCase" safePrefix="value"/> <ModuleName case="originalCase" safePrefix="mod"/> <PackageName case="originalCase" safePrefix="v"/> </Conventions> <Substitutions> <Substitution type="package" search="http://www.w3.org/2001/XMLSchema" replace="xs"/> <Substitution type="package" search="http://www.w3.org/XML/1998/namespace" replace="xml"/> <Substitution type="package" search="http://www.w3.org/2001/XMLSchema-instance" replace="xsi"/> <Substitution type="package" search="http://www.w3.org/1998/Math/MathML" replace="mathml3"/> <Substitution type="package" search="http://www.w3.org/1999/xlink" replace="xlink"/> <Substitution type="package" search="http://www.w3.org/1999/xhtml" replace="xhtml"/> <Substitution type="package" search="http://schemas.xmlsoap.org/wsdl/soap/" replace="soap"/> <Substitution type="package" search="http://schemas.xmlsoap.org/wsdl/soap12/" replace="soap12"/> <Substitution type="package" search="http://schemas.xmlsoap.org/soap/envelope/" replace="soapenv"/> <Substitution type="package" search="http://schemas.xmlsoap.org/soap/encoding/" replace="soapenc"/> <Substitution type="module" search="(.*)Class$" replace="1Type"/> </Substitutions> <Extensions/> <Resources> <Exclude>schemas/skip/*.xsd</Exclude> </Resources> </Config>
MRE:
#schemas/test/test.xsd:
<?xml version="1.0" encoding="UTF-8"?> <xsd:schema targetNamespace="http://www.test.com/sample" xmlns="http://www.test.com/sample" xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified" version="1.0"> <xsd:annotation> <xsd:documentation> <Description>Test Schema - A few sample base types</Description> </xsd:documentation> </xsd:annotation> <!-- String Type --> <xsd:simpleType name="StringType"> <xsd:annotation> <xsd:documentation>Base type for a string</xsd:documentation> </xsd:annotation> <xsd:restriction base="xsd:string" /> </xsd:simpleType> <!-- Boolean Type - true or false, or 1 or 0 --> <xsd:simpleType name="BooleanType"> <xsd:annotation> <xsd:documentation>Base type for a boolean. Typically used on an Yes or No field.</xsd:documentation> </xsd:annotation> <xsd:restriction base="xsd:boolean" /> </xsd:simpleType> <!-- Checkbox Type --> <xsd:simpleType name="CheckboxType"> <xsd:annotation> <xsd:documentation>Typically used by an optional checkbox.</xsd:documentation> </xsd:annotation> <xsd:restriction base="xsd:string"> <xsd:enumeration value="X" /> </xsd:restriction> </xsd:simpleType> <!-- Integer Type --> <xsd:simpleType name="IntegerType"> <xsd:annotation> <xsd:documentation>Base type for an integer</xsd:documentation> </xsd:annotation> <xsd:restriction base="xsd:integer"> <xsd:totalDigits value="25"/> </xsd:restriction> </xsd:simpleType> <!-- Amount Type --> <xsd:simpleType name="AmountType"> <xsd:annotation> <xsd:documentation>Type for an integer amount field</xsd:documentation> </xsd:annotation> <xsd:restriction base="xsd:integer"> <xsd:totalDigits value="15"/> </xsd:restriction> </xsd:simpleType> <!-- Type for a Structured Itemized Amount --> <xsd:complexType name="ItemizedAmountType"> <xsd:sequence> <xsd:element name="Desc" type="LineExplanationType" /> <xsd:element name="Amt" type="AmountType" /> </xsd:sequence> </xsd:complexType> </xsd:schema>
Output for complexType (I get nothing for simpleTypes):
@dataclass class ItemizedAmountType: Desc: Optional[str] = field( default=None, metadata={ "type": "Element", "namespace": "http://www.test.com/sample", "required": True, "max_length": 100, "pattern": r"([!-~£§ÁÉÍÑÓ×ÚÜáéíñóúü] ?)*[!-~£§ÁÉÍÑÓ×ÚÜáéíñóúü]", }, ) Amt: Optional[int] = field( default=None, metadata={ "type": "Element", "namespace": "http://www.test.com/sample", "required": True, "total_digits": 17, }, )
Please excuse the newb status. I’m a year or so into programming and have slipped into the deep end of the wading pool. I’ve learned more than i expected, but still don’t know what i don’t know.
All input is MUCH appreciated!
submitted by /u/Popular_Impression56
[link] [comments]
r/learnpython Hi all– I’m trying to diff a few thousand xsd files and was excited to try [xsData toolkit](https://xsdata.readthedocs.io/en/latest/) to see if diffing pre-db dataclass files would be easier than diffing parsed/stored xsd’s. Everything was going great…until i realized xsData is only processing complexTypes and not simpleTypes. My MRE & config is posted below, but I’m thinking that I should first ask: Does xsdata require some type of external extension in order to process simpleTypes? Am i missing something basic about the limitations of parsing simpleTypes? It’s also possible that i’m not configured correctly for base type restrictions? I’m struggling with xsdata’s docs. They offer little in terms of config options, use cases, etc, so it’s hard for me to gauge whether or not this will require a config tag, plugin, or custom parser. I’ve found few/no workable answers on stackoverflow. .xsdata.xml for reference: <?<?xml version=”1.0″ encoding=”UTF-8″?> <Config xmlns=”http://pypi.org/project/xsdata” version=”24.11″> <Output maxLineLength=”320″ genericCollections=”false” unionType=”false”> <Format repr=”true” eq=”true” order=”false” unsafeHash=”false” frozen=”false” slots=”false” kwOnly=”false”>dataclasses</Format> <PostponedAnnotations>false</PostponedAnnotations> <Structure>filenames</Structure> <DocstringStyle>Accessible</DocstringStyle> <RelativeImports>false</RelativeImports> <CompoundFields defaultName=”values” useSubstitutionGroups=”false” forceDefaultName=”false” maxNameParts=”3″>true</CompoundFields> <WrapperFields>true</WrapperFields> <UnnestClasses>true</UnnestClasses> <IgnorePatterns>false</IgnorePatterns> <IncludeHeader>false</IncludeHeader> </Output> <Conventions> <ClassName case=”originalCase” safePrefix=”type”/> <FieldName case=”originalCase” safePrefix=”value”/> <ConstantName case=”originalCase” safePrefix=”value”/> <ModuleName case=”originalCase” safePrefix=”mod”/> <PackageName case=”originalCase” safePrefix=”v”/> </Conventions> <Substitutions> <Substitution type=”package” search=”http://www.w3.org/2001/XMLSchema” replace=”xs”/> <Substitution type=”package” search=”http://www.w3.org/XML/1998/namespace” replace=”xml”/> <Substitution type=”package” search=”http://www.w3.org/2001/XMLSchema-instance” replace=”xsi”/> <Substitution type=”package” search=”http://www.w3.org/1998/Math/MathML” replace=”mathml3″/> <Substitution type=”package” search=”http://www.w3.org/1999/xlink” replace=”xlink”/> <Substitution type=”package” search=”http://www.w3.org/1999/xhtml” replace=”xhtml”/> <Substitution type=”package” search=”http://schemas.xmlsoap.org/wsdl/soap/” replace=”soap”/> <Substitution type=”package” search=”http://schemas.xmlsoap.org/wsdl/soap12/” replace=”soap12″/> <Substitution type=”package” search=”http://schemas.xmlsoap.org/soap/envelope/” replace=”soapenv”/> <Substitution type=”package” search=”http://schemas.xmlsoap.org/soap/encoding/” replace=”soapenc”/> <Substitution type=”module” search=”(.*)Class$” replace=”1Type”/> </Substitutions> <Extensions/> <Resources> <Exclude>schemas/skip/*.xsd</Exclude> </Resources> </Config> MRE: #schemas/test/test.xsd: <?xml version=”1.0″ encoding=”UTF-8″?> <xsd:schema targetNamespace=”http://www.test.com/sample” xmlns=”http://www.test.com/sample” xmlns:xsd=”http://www.w3.org/2001/XMLSchema” elementFormDefault=”qualified” attributeFormDefault=”unqualified” version=”1.0″> <xsd:annotation> <xsd:documentation> <Description>Test Schema – A few sample base types</Description> </xsd:documentation> </xsd:annotation> <!– String Type –> <xsd:simpleType name=”StringType”> <xsd:annotation> <xsd:documentation>Base type for a string</xsd:documentation> </xsd:annotation> <xsd:restriction base=”xsd:string” /> </xsd:simpleType> <!– Boolean Type – true or false, or 1 or 0 –> <xsd:simpleType name=”BooleanType”> <xsd:annotation> <xsd:documentation>Base type for a boolean. Typically used on an Yes or No field.</xsd:documentation> </xsd:annotation> <xsd:restriction base=”xsd:boolean” /> </xsd:simpleType> <!– Checkbox Type –> <xsd:simpleType name=”CheckboxType”> <xsd:annotation> <xsd:documentation>Typically used by an optional checkbox.</xsd:documentation> </xsd:annotation> <xsd:restriction base=”xsd:string”> <xsd:enumeration value=”X” /> </xsd:restriction> </xsd:simpleType> <!– Integer Type –> <xsd:simpleType name=”IntegerType”> <xsd:annotation> <xsd:documentation>Base type for an integer</xsd:documentation> </xsd:annotation> <xsd:restriction base=”xsd:integer”> <xsd:totalDigits value=”25″/> </xsd:restriction> </xsd:simpleType> <!– Amount Type –> <xsd:simpleType name=”AmountType”> <xsd:annotation> <xsd:documentation>Type for an integer amount field</xsd:documentation> </xsd:annotation> <xsd:restriction base=”xsd:integer”> <xsd:totalDigits value=”15″/> </xsd:restriction> </xsd:simpleType> <!– Type for a Structured Itemized Amount –> <xsd:complexType name=”ItemizedAmountType”> <xsd:sequence> <xsd:element name=”Desc” type=”LineExplanationType” /> <xsd:element name=”Amt” type=”AmountType” /> </xsd:sequence> </xsd:complexType> </xsd:schema> Output for complexType (I get nothing for simpleTypes): @dataclass class ItemizedAmountType: Desc: Optional[str] = field( default=None, metadata={ “type”: “Element”, “namespace”: “http://www.test.com/sample”, “required”: True, “max_length”: 100, “pattern”: r”([!-~£§ÁÉÍÑÓ×ÚÜáéíñóúü] ?)*[!-~£§ÁÉÍÑÓ×ÚÜáéíñóúü]”, }, ) Amt: Optional[int] = field( default=None, metadata={ “type”: “Element”, “namespace”: “http://www.test.com/sample”, “required”: True, “total_digits”: 17, }, ) Please excuse the newb status. I’m a year or so into programming and have slipped into the deep end of the wading pool. I’ve learned more than i expected, but still don’t know what i don’t know. All input is MUCH appreciated! submitted by /u/Popular_Impression56 [link] [comments]
Hi all– I’m trying to diff a few thousand xsd files and was excited to try [xsData toolkit](https://xsdata.readthedocs.io/en/latest/) to see if diffing pre-db dataclass files would be easier than diffing parsed/stored xsd’s.
Everything was going great…until i realized xsData is only processing complexTypes and not simpleTypes. My MRE & config is posted below, but I’m thinking that I should first ask:
Does xsdata require some type of external extension in order to process simpleTypes?
Am i missing something basic about the limitations of parsing simpleTypes? It’s also possible that i’m not configured correctly for base type restrictions?
I’m struggling with xsdata’s docs. They offer little in terms of config options, use cases, etc, so it’s hard for me to gauge whether or not this will require a config tag, plugin, or custom parser. I’ve found few/no workable answers on stackoverflow.
.xsdata.xml for reference:
<?<?xml version="1.0" encoding="UTF-8"?> <Config xmlns="http://pypi.org/project/xsdata" version="24.11"> <Output maxLineLength="320" genericCollections="false" unionType="false"> <Format repr="true" eq="true" order="false" unsafeHash="false" frozen="false" slots="false" kwOnly="false">dataclasses</Format> <PostponedAnnotations>false</PostponedAnnotations> <Structure>filenames</Structure> <DocstringStyle>Accessible</DocstringStyle> <RelativeImports>false</RelativeImports> <CompoundFields defaultName="values" useSubstitutionGroups="false" forceDefaultName="false" maxNameParts="3">true</CompoundFields> <WrapperFields>true</WrapperFields> <UnnestClasses>true</UnnestClasses> <IgnorePatterns>false</IgnorePatterns> <IncludeHeader>false</IncludeHeader> </Output> <Conventions> <ClassName case="originalCase" safePrefix="type"/> <FieldName case="originalCase" safePrefix="value"/> <ConstantName case="originalCase" safePrefix="value"/> <ModuleName case="originalCase" safePrefix="mod"/> <PackageName case="originalCase" safePrefix="v"/> </Conventions> <Substitutions> <Substitution type="package" search="http://www.w3.org/2001/XMLSchema" replace="xs"/> <Substitution type="package" search="http://www.w3.org/XML/1998/namespace" replace="xml"/> <Substitution type="package" search="http://www.w3.org/2001/XMLSchema-instance" replace="xsi"/> <Substitution type="package" search="http://www.w3.org/1998/Math/MathML" replace="mathml3"/> <Substitution type="package" search="http://www.w3.org/1999/xlink" replace="xlink"/> <Substitution type="package" search="http://www.w3.org/1999/xhtml" replace="xhtml"/> <Substitution type="package" search="http://schemas.xmlsoap.org/wsdl/soap/" replace="soap"/> <Substitution type="package" search="http://schemas.xmlsoap.org/wsdl/soap12/" replace="soap12"/> <Substitution type="package" search="http://schemas.xmlsoap.org/soap/envelope/" replace="soapenv"/> <Substitution type="package" search="http://schemas.xmlsoap.org/soap/encoding/" replace="soapenc"/> <Substitution type="module" search="(.*)Class$" replace="1Type"/> </Substitutions> <Extensions/> <Resources> <Exclude>schemas/skip/*.xsd</Exclude> </Resources> </Config>
MRE:
#schemas/test/test.xsd:
<?xml version="1.0" encoding="UTF-8"?> <xsd:schema targetNamespace="http://www.test.com/sample" xmlns="http://www.test.com/sample" xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified" version="1.0"> <xsd:annotation> <xsd:documentation> <Description>Test Schema - A few sample base types</Description> </xsd:documentation> </xsd:annotation> <!-- String Type --> <xsd:simpleType name="StringType"> <xsd:annotation> <xsd:documentation>Base type for a string</xsd:documentation> </xsd:annotation> <xsd:restriction base="xsd:string" /> </xsd:simpleType> <!-- Boolean Type - true or false, or 1 or 0 --> <xsd:simpleType name="BooleanType"> <xsd:annotation> <xsd:documentation>Base type for a boolean. Typically used on an Yes or No field.</xsd:documentation> </xsd:annotation> <xsd:restriction base="xsd:boolean" /> </xsd:simpleType> <!-- Checkbox Type --> <xsd:simpleType name="CheckboxType"> <xsd:annotation> <xsd:documentation>Typically used by an optional checkbox.</xsd:documentation> </xsd:annotation> <xsd:restriction base="xsd:string"> <xsd:enumeration value="X" /> </xsd:restriction> </xsd:simpleType> <!-- Integer Type --> <xsd:simpleType name="IntegerType"> <xsd:annotation> <xsd:documentation>Base type for an integer</xsd:documentation> </xsd:annotation> <xsd:restriction base="xsd:integer"> <xsd:totalDigits value="25"/> </xsd:restriction> </xsd:simpleType> <!-- Amount Type --> <xsd:simpleType name="AmountType"> <xsd:annotation> <xsd:documentation>Type for an integer amount field</xsd:documentation> </xsd:annotation> <xsd:restriction base="xsd:integer"> <xsd:totalDigits value="15"/> </xsd:restriction> </xsd:simpleType> <!-- Type for a Structured Itemized Amount --> <xsd:complexType name="ItemizedAmountType"> <xsd:sequence> <xsd:element name="Desc" type="LineExplanationType" /> <xsd:element name="Amt" type="AmountType" /> </xsd:sequence> </xsd:complexType> </xsd:schema>
Output for complexType (I get nothing for simpleTypes):
@dataclass class ItemizedAmountType: Desc: Optional[str] = field( default=None, metadata={ "type": "Element", "namespace": "http://www.test.com/sample", "required": True, "max_length": 100, "pattern": r"([!-~£§ÁÉÍÑÓ×ÚÜáéíñóúü] ?)*[!-~£§ÁÉÍÑÓ×ÚÜáéíñóúü]", }, ) Amt: Optional[int] = field( default=None, metadata={ "type": "Element", "namespace": "http://www.test.com/sample", "required": True, "total_digits": 17, }, )
Please excuse the newb status. I’m a year or so into programming and have slipped into the deep end of the wading pool. I’ve learned more than i expected, but still don’t know what i don’t know.
All input is MUCH appreciated!
submitted by /u/Popular_Impression56
[link] [comments]