title: XSD for a tree of string key-value pairs
body: <p>I'd like to build a XSD for a tree of string key-value pairs.
  Something to fit this:</p>
  
  <pre><code>&lt;entry&gt;
    &lt;key&gt;root&lt;/key&gt;
      &lt;entry key="name"&gt;john&lt;/entry&gt;
      &lt;entry key="address"&gt;
        &lt;entry key="street"&gt;Rou de Flon 1&lt;/entry&gt;
        &lt;entry key="city"&gt;Lausanne&lt;/entry&gt;
     &lt;/entry&gt;
  &lt;/entry&gt;
  </code></pre>
  
  <p>I didn't manage to get this (I want to use xsd:string, and not xsd:anyType)</p>
  
  <p>This alternative pattern:</p>
  
  <pre><code>&lt;entry&gt;
    &lt;key&gt;root&lt;/key&gt;
      &lt;entry&gt;
        &lt;key&gt;name&lt;/key&gt;
        &lt;value&gt;john&lt;/value&gt;
      &lt;/entry&gt;
      &lt;entry&gt;
        &lt;key&gt;address&lt;/key&gt;
        &lt;entry&gt;
          &lt;key&gt;street&lt;/key&gt;
          &lt;value&gt;Rou de Flon 1&lt;/value&gt;
        &lt;/entry&gt;
        &lt;entry&gt;
          &lt;key&gt;city&lt;/key&gt;
          &lt;value&gt;Lausanne&lt;/value&gt;
        &lt;/entry&gt;
     &lt;/entry&gt;
  &lt;/entry&gt;
  </code></pre>
  
  <p>can be done with:</p>
  
  <pre><code>  &lt;xsd:complexType name="Entry"&gt;
      &lt;xsd:sequence&gt;
        &lt;xsd:element name="key" type="xsd:string"/&gt;
        &lt;xsd:choice&gt;
          &lt;xsd:element name="value" type="xsd:string"/&gt;
          &lt;xsd:element name="entry" maxOccurs="unbounded" type="rbo:Entry"/&gt;
        &lt;/xsd:choice&gt;
      &lt;/xsd:sequence&gt;
    &lt;/xsd:complexType&gt;
  </code></pre>
  
  <p>but I would prefer to use the first pattern, because it is more compact.</p>
  
  <p>I tried this other XSD:</p>
  
  <pre><code>  &lt;xsd:complexType name="ValueEntry"&gt;
      &lt;xsd:simpleContent&gt;
        &lt;xsd:extension base="xsd:string"&gt;
          &lt;xsd:attribute name="key" use="required" type="xsd:string"/&gt;
        &lt;/xsd:extension&gt;
      &lt;/xsd:simpleContent&gt;
    &lt;/xsd:complexType&gt;
  
    &lt;xsd:complexType name="ListEntry"&gt;
      &lt;xsd:sequence&gt;
        &lt;xsd:element name="entry" maxOccurs="unbounded" type="rbo:ListOrValueEntry"/&gt;
      &lt;/xsd:sequence&gt;
      &lt;xsd:attribute name="key" use="required" type="xsd:string"/&gt;
    &lt;/xsd:complexType&gt;
  
    &lt;xsd:complexType name="ListOrValueEntry"&gt;
      &lt;xsd:sequence&gt;
        &lt;xsd:choice&gt;
          &lt;xsd:element name="value" type="rbo:ValueEntry"/&gt;
          &lt;xsd:element name="entry" type="rbo:ListEntry"/&gt;
        &lt;/xsd:choice&gt;
      &lt;/xsd:sequence&gt;
    &lt;/xsd:complexType&gt;
  </code></pre>
  
  <p>but it produces more ugly XML:</p>
  
  <pre><code>&lt;listEntry&gt;
    &lt;entry&gt;
      &lt;value key="name"&gt;john&lt;/value&gt;
    &lt;/entry&gt;
    &lt;entry&gt;
      &lt;entry key="address"&gt;
        &lt;entry&gt;
          &lt;value key="street"&gt;Rou de Flon 1&lt;/value&gt;
        &lt;/entry&gt;
        &lt;entry&gt;
          &lt;value key="city"&gt;Lausanne&lt;/value&gt;
        &lt;/entry&gt;
      &lt;/entry&gt;
    &lt;/entry&gt;
  &lt;/listEntry&gt;
  </code></pre>
  
  <p>So, is there a way to create a XSD for this pattern, without using xsd:anyType?</p>
  
  <pre><code>&lt;entry&gt;
    &lt;key&gt;root&lt;/key&gt;
      &lt;entry key="name"&gt;john&lt;/entry&gt;
      &lt;entry key="address"&gt;
        &lt;entry key="street"&gt;Rou de Flon 1&lt;/entry&gt;
        &lt;entry key="city"&gt;Lausanne&lt;/entry&gt;
     &lt;/entry&gt;
  &lt;/entry&gt;
  </code></pre>
  
  <p>ps: please, don't discuss whether you like this pattern or not; that's a nice discussion, but it is not the objective of this post.
  the objective of this post is to find out how to, if at all possible, write XSD for this XML, without using xsd:anyType.</p>