Giter Site home page Giter Site logo

Generate classes for element groups about xsdata HOT 5 OPEN

skinkie avatar skinkie commented on September 13, 2024
Generate classes for element groups

from xsdata.

Comments (5)

tefra avatar tefra commented on September 13, 2024

Groups of elements are flattened @skinkie so it becomes a choice of two sequences

from xsdata.

skinkie avatar skinkie commented on September 13, 2024

Groups of elements are flattened @skinkie so it becomes a choice of two sequences

Which is obviously not what was intended. What should be used if I would like to see them as a choice between two sets of elements?

from xsdata.

skinkie avatar skinkie commented on September 13, 2024

When reading the code the code now flattens groups, and then removes them.

I have created this rather simple form of the use case.

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns="http://www.netex.org.uk/netex" xmlns:netex="http://www.netex.org.uk/netex" xmlns:siri="http://www.siri.org.uk/siri" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.netex.org.uk/netex" elementFormDefault="qualified" attributeFormDefault="unqualified" version="1.1" id="netex_datedPassingTimes_version">
	<xsd:element name="Test">
		<xsd:complexType>
			<xsd:sequence>
				<xsd:choice>
					<xsd:group ref="TargetTimesAtStopGroup">
						<xsd:annotation>
							<xsd:documentation>Aimed Times at stop.</xsd:documentation>
						</xsd:annotation>
					</xsd:group>
					<xsd:group ref="NonStopTimesAtStopGroup"/>
				</xsd:choice>
			</xsd:sequence>
		</xsd:complexType>
	</xsd:element>
	<xsd:group name="TargetTimesAtStopGroup">		
                <xsd:annotation>
                        <xsd:documentation>Times at stop elements.</xsd:documentation>
                </xsd:annotation>
                <xsd:sequence>
                        <xsd:element name="AimedArrivalTime" type="xsd:time" minOccurs="0">
                                <xsd:annotation>
                                        <xsd:documentation>Aimed Arrival time.</xsd:documentation>
                                </xsd:annotation>
                        </xsd:element>
                        <xsd:element name="AimedDepartureTime" type="xsd:time" minOccurs="0">
                                <xsd:annotation>
                                        <xsd:documentation>Aimed departure time.</xsd:documentation>
                                </xsd:annotation>
                        </xsd:element>
                        <xsd:element name="AimedWaitingTime" type="xsd:duration" minOccurs="0">
                                <xsd:annotation>
                                        <xsd:documentation>Aimed waiting interval.</xsd:documentation>
                                </xsd:annotation>
                        </xsd:element>
                </xsd:sequence>
        </xsd:group>
        <xsd:group name="NonStopTimesAtStopGroup">
                <xsd:annotation>
                        <xsd:documentation>Times at stop elements.</xsd:documentation>
                </xsd:annotation>
                <xsd:sequence>
                        <xsd:element name="AimedNonstopPassingTime" type="xsd:time" minOccurs="0">
                                <xsd:annotation>
                                        <xsd:documentation>Aimed PASSING TIME if doesn't stop at TIMING POINT.</xsd:documentation>
                                </xsd:annotation>
                        </xsd:element>
                </xsd:sequence>
        </xsd:group>	
</xsd:schema>

I am looking for something like this as the output:

            "choices": (
                {
                    "name": "TargetTimesAtStopGroup",
                    "type": Type[
                        "TargetTimesAtStopGroup"
                    ],
                    "namespace": "http://www.netex.org.uk/netex",
                },
                {
                    "name": "NonStopTimesAtStopGroup",
                    "type": Type[
                        "NonStopTimesAtStopGroup"
                    ],
                    "namespace": "http://www.netex.org.uk/netex",
                },

I guess for this to happen the analyser should mark groups within a choice as something special, to later upgrade them into a type which would get its own class.

from xsdata.

tefra avatar tefra commented on September 13, 2024

Yeah and the xml parser/serializer has to recognize and ignore the group classes. We would need to implement something like the wrappers but for groups.

Honestly I don't like the approach. xsdata philosophy is to simplify xml schemas not replicate all their quirks into python. Some of them like circular references would be impossible to tackle otherwise.

I am going to leave this issue open as a feature request, but don't hold your breath.

from xsdata.

skinkie avatar skinkie commented on September 13, 2024

Yeah and the xml parser/serializer has to recognize and ignore the group classes. We would need to implement something like the wrappers but for groups.

Thanks, I'll investigate.

Honestly I don't like the approach. xsdata philosophy is to simplify xml schemas not replicate all their quirks into python. Some of them like circular references would be impossible to tackle otherwise.

My aim for this project would be to have an object-oriented output of an XML Schema. The flattening is, where there is more than one group, does not do just to the XML Schema in this particular case. I can find some other cases where it certainly makes sense to flatten it. (AllSubModeChoiceGroup)

I am going to leave this issue open as a feature request, but don't hold your breath.

I have just researched how and when this is done within the NeTEx schema, it is not that often.
NeTEx-CEN/NeTEx#669

from xsdata.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.