2
votes

I am trying to design an XML structure to capture the output from a spreadsheet which contains a Customer Name and many different amount columns. And there is a total row as well.

I have about 4 amounts column definitions that I want to reuse as a group. So, I declared a group called AmountsGroup and then used the Group Name as a 'ref' attribute inside my complex type definition. Here is how it looks like

<xsd:complexType name="AmountByCustomerType">
    <xsd:sequence>
        <xsd:element name="Customer" type="xsd:string" />
        <xsd:group ref="AmountsGroup" maxOccurs="unbounded"/>
    </xsd:sequence>
</xsd:complexType>

<xsd:complexType name="AmountByCustomerTotalType">
    <xsd:sequence>
        <xsd:element name="Total" type="xsd:string" />
        <xsd:group ref="AmountsGroup" />
    </xsd:sequence>
</xsd:complexType>

<xsd:group name="AmountsGroup">
    <xsd:sequence>
        <xsd:element name="AmountByPeriod" type="AmountByPeriodType" maxOccurs="unbounded" />
        <xsd:element name="NetAdjustments" type="xsd:decimal" />
        <xsd:element name="OriginalSalesAmount" type="xsd:decimal" minOccurs="0"/>
        <xsd:element name="RevisedAmount" type="xsd:decimal" />
    </xsd:sequence>        
</xsd:group>

Here are my questions:

  1. I have declared the group as having maxOccurs="unbounded" in the first complexType where in the second complexType I have left it out meaning it will have to occur only once. Will this work correctly? I want many rows of customer amount and only one total amount row.

  2. The XML instance document will not need to have the name of this group name anywhere - is that correct?

  3. Is there any better way to structure the individual rows and total type of structure?

  4. Is this a good practice when I use Venetian Blinds Pattern? I don't want to declare a complexType since then I have to declare an element which will appear in the XML instance document, thus adding one more level to the XML object tree. Is there any way to use a named Type without giving it an element on its own? I hope you understand what I am trying to do.

Any thoughts?

1

1 Answers

2
votes
  1. Correct, maxOccurs applies to the group as a whole.

  2. Correct, group name is in the schema only.

  3. I was going to suggest introducing an element to encapsulate the group members, but I see from your 4th question you're trying to avoid that. I prefer it since it makes it easier for a parser to identify the start and end of each "row" and mirrors programming encapsulation.

  4. Seems reasonable; you're still keeping with the Venetian Blinds spirit of reusable components without committing to a namespace for local elements.