1

I need to use pattern for an attribute and for text. But how? Some example of my XML:

<?xml version="1.0" encoding="utf-8"?>
<main>
  <Number attribute="45454">a</Number>
  <Number attribute="66666">b</Number>
  <Model attribute="12476">c</Model>
  <Model attribute="12476">c</Model>
</main>

Text contains only one letter:

      <xs:element maxOccurs="unbounded" name="Number">
       <xs:simpleType>
          <xs:restriction base="xs:string">
            <xs:pattern value="[a-zA-Z]{1}"/>
          </xs:restriction>
        </xs:simpleType>
      </xs:element>

Attribute contains 5 digits:

<xs:element maxOccurs="unbounded" name="Model">
  <xs:complexType>
    <xs:simpleContent>
      <xs:extension base="xs:string">
        <xs:attribute name="attribute">
          <xs:simpleType>
            <xs:restriction base="xs:integer">
              <xs:pattern value="\d{5}"/>
            </xs:restriction>
          </xs:simpleType>
        </xs:attribute>
      </xs:extension>
    </xs:simpleContent>
  </xs:complexType>
</xs:element>

I can restrict only attribute or text, not both. How i can do it?

Jake
  • 11
  • 2
  • See specifically the section of [**this answer**](http://stackoverflow.com/a/33303107/290085) with the heading, ***How to restrict element content when element has attribute*** – kjhughes Feb 10 '17 at 15:06

0 Answers0