Title: How to allow an attribute on an element with string content?
Tags: xml;parsing;xsd;xml-validation
Question: I'm trying to write an XSD for the following XML:

```  <users&gt;
    <user id='u1'&gt;A</user&gt;
    <user id='u2'&gt;B</user&gt;
    <user id='u3'&gt;C</user&gt;
  </users&gt;
```

Here is what I have so far:

```<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
        <xsd:element name="users"&gt;
          <xsd:complexType&gt;
            <xsd:sequence&gt;
              <xsd:element name="user" maxOccurs="unbounded" type="xsd:string"&gt;
                <xsd:attribute name="id" type="xsd:string"/&gt;
              </xsd:element&gt;
            </xsd:sequence&gt;
          </xsd:complexType&gt;
        </xsd:element&gt;
</xsd:schema&gt;
```

But it returns errror: 

```
  Element
  '{http://www.w3.org/2001/XMLSchema}element': The content is not valid.
  Expected is (annotation?, ((simpleType | complexType)?, (unique | key
  | keyref)*))
```

The id attribute is the id of user.
Any idea how I can fix this?


Here is the accepted answer: Here is how to define an element with ```simpleContent``` (```xsd:string```) and an attribute in XSD:

```<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
  <xsd:element name="users"&gt;
    <xsd:complexType&gt;
      <xsd:sequence&gt;
        <xsd:element name="user" maxOccurs="unbounded"&gt;
          <xsd:complexType&gt;
            <xsd:simpleContent&gt;
              <xsd:extension base="xsd:string"&gt;
                <xsd:attribute name="id" type="xsd:string"/&gt;
              </xsd:extension&gt;
            </xsd:simpleContent&gt;
          </xsd:complexType&gt;
        </xsd:element&gt;
      </xsd:sequence&gt;
    </xsd:complexType&gt;
  </xsd:element&gt;
</xsd:schema&gt;
```

(Your error has nothing to do with ```maxOccurs``` being unbounded.  It had to do with the content model of your ```user``` element.)



{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2015:00:12/14/15', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<xml><parsing><xsd><xml-validation>', 'Title': 'How to allow an attribute on an element with string content?', 'ViewCount': 468, 'id': 34268492, 'user_AboutMe': '', 'user_AccountId': 7014696.0, 'user_DisplayName': 'Alex B.', 'user_Reputation': 69.0, 'user_Views': 6.0, 'user_id': 5376456.0}}