Here is an XSD - is its grammar the clearest approach?
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="object">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="string">
<xs:complexType>
<xs:attribute name="name" type="xs:string"/>
<xs:attribute name="value" type="xs:string"/>
</xs:complexType>
</xs:element>
<xs:element ref="object"/>
</xs:choice>
<xs:attribute name="name" type="xs:string"/>
</xs:complexType>
</xs:element>
</xs:schema>
The basic idea of the XML is nested objects:
V --> string | O // a Value is a string or an Object
O --> (K V)* // an Object is list of named values (Key-Value pairs)
But it's slightly different, in that the root is always an Object (not a string), and it itself is named (even though it isn't inside another Object):
O ==> (string K | O)* K
I am open to changing the format itself slightly, to give different XML, if that will make a simpler/clearer XSD. If an Object always has a name, this removes special cases, which makes the grammar and XSD more regular - and simpler. Therefore, it seems simpler for an Object to always have a name.
Clarification: the special case would be that when the Object is the root it is not named, but in all other cases it is named. This requires an extra header section, like this:
O'==> (string K | O)*
O ==> (string K | O)* K
Handling this special case is more complex than the original, even when refactored to minimize that complexity:
F ==> (string K | O)*
O ==> F K