First question (be kind!) Explanation: if a property's true, I need the type to have elements. So if an attribute is true, the XML output might be:
<Approval Approved="true">
<By>RT</By>
<Date>27/07/2011</Date>
</Approval>
And if it isn't approved, the XML output might be
<Approval Approved="false" />
Is it possible to specify something like this in an XSD?
Turns out, you can do it (sort of) but the method totally sucks.
Had to make two complex types (one with the Approved tag and one without), change the root element and allow switching between the two types like this:
<xs:element name="ArchivedFormulation">
<xs:complexType>
<xs:choice>
<xs:element name="ApprovedFormulation" type="ApprovedFormulation" />
<xs:element name="NonApprovedFormulation" type="NonApprovedFormulation" />
</xs:choice>
</xs:complexType>
Could add the complex types using XSD inheritance.
<xs:complexType name="ApprovedFormulation">
<xs:complexContent>
<xs:extension base="NonApprovedFormulation">
<xs:sequence>
<xs:element name="Approved" minOccurs="1" maxOccurs="1">
<xs:complexType>
<xs:sequence>
<xs:element name="ApprovedBy" type="xs:string" />
<xs:element name="ApprovedOn" type="xs:date" />
</xs:sequence>
<xs:attribute name="IsApproved" type="xs:boolean" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:extension>
</xs:complexContent>
That gave me what I wanted.