Specifying output order for xml objects
Question asked by Scott Zrubek - July 20 at 8:22 PM
Answered
I have an issue where I need to output a set of objects in the order in which they were input.  I'm trying to determine if there is a way within the objects created by liquid from an xsd to add a key that allows me to specify the order for output.  

To summary, we have one object that can contain an unknown number of 4 types of subobjects.  Those 4 subobjects are used to generate a mathematical formula.  I have a table that keeps track of the order of those subobjects as they come in.  Currently, the exporter exports the objects grouped by object type.  They are sorted properly within the object type, but I need the exporter to ignore the grouping by object type and output by a specific order.  How do I tell the exporter to do that.

Below is a subset of the XSD, a subset of the input file, and how the output is currently generated.

	<complexType name="MainType">
		<annotation>
			<documentation xml:lang="en">
                        Describe a mathematical function.                   
                        </documentation>
		</annotation>
		<complexContent>
			<extension base="xtce:BaseType">
				<choice maxOccurs="unbounded">
					<element name="Subtype1" type="type1">
					</element>
					<element name="Subtype2" type="type2">
					</element>
					<element name="Subtype3" type="type3">
					</element>
					<element name="Subtype4" type="type4">
					</element>
				</choice>
			</extension>
		</complexContent>
	</complexType>

        Input file, and desired output

	<MainType>
		<Subtype1>aaa</Subtype1>
		<Subtype2>bbb</Subtype2>
		<Subtype1>ccc</Subtype1>
		<Subtype2>ddd</Subtype2>
		<Subtype3>eee</Subtype3>
		<Subtype4>fff</Subtype4>
		<Subtype3>ggg</Subtype3>
		<Subtype1>hhh</Subtype1>
	</MainType>

        Current output file

	<MainType>
		<Subtype1>aaa</Subtype1>
		<Subtype1>ccc</Subtype1>
		<Subtype1>hhh</Subtype1>
		<Subtype2>ddd</Subtype2>
		<Subtype2>bbb</Subtype2>
		<Subtype3>eee</Subtype3>
		<Subtype3>ggg</Subtype3>
		<Subtype4>fff</Subtype4>
	</MainType>

2 Replies

Reply to Thread
0
Liquid Support Replied
Employee Post Marked As Answer
The default generation model uses the "Simplified Model", this makes reading and writing very simple, but at the expense of losing some ordering information.


Generating the code using the "High Conformance Model", will allow you access to the data as described by the XSD. This is a little more verbose but allows to retain the more subtle aspects of the XSD, including ordering. Given you are working with mathematical formula, it seems likely you need deal with more subtle aspects of the XML when reading/writing the data, so this is the way to go.


See Code Generation Models for more details


0
Scott Zrubek Replied
So I need to regenerate the code from the XSD using High Conformance and should then be able to track sequence.  I'm glad there's a solution!  I hope it's not too much work.

Reply to Thread